Rewriting git history to unpack compressed commit

At the moment I have a branch developthat contains compressed union merger 30 a commit from another branch develop-2. This squeezed latch is not on HEAD, perhaps 20-30 or so will happen before HEAD. I still have a branch develop-2with all the individual commits that it consists of.

How do I perform a Git operation in this repository to β€œunzip” a compressed commit and replace it in the Git history with its individual commits from the branch develop-2?

+4
source share
3 answers

I would check the commit before the crushed commit, create a branch and merge your uncommitted commits.

Then git cherry-pickthe commit range from your old story on top of this new branch.

Something like the following.

B' = squashed b2
        A     B'    C    D
dev - - * - - * - - * -- *
dev2    \ - - * - - * - - *
               b1    b2    b3

Step 1 & 2: `git checkout <sha-A> && git checkout -b d3  && git merge dev2`
        A     B'    C    D
dev - - * - - * - - * -- *
d3  - - * - - b1 - - b2 - - b3

Step 3: `git cherry-pick <sha B'>..dev`
d3  - - A - - b1 - - b2 - - b3 - - C - - D

The above actions do not destroy your current branches.

+3
source

Do not use too much 'git rebase -onto'

0
source

Suppose your branch structure is shown below the graph (C - squash merge from develop-2):

A---C0---B---C’---D---...---X  develop
     \         
      C1---C2---...---C30      develop-2

You can use these steps to unzip C’on a branch develop:

1. git rebase --onto <commit id for B> <commit id for C0> <commit id for C30>

           C1’---C2’---...---C30’  HEAD
          /
A---C0---B---C’---D---...---X      develop
     \         
      C1---C2---...---C30          develop-2

2. git rebase --onto <commit id now HEAD is> <commit id for C’> develop

A---C0---B---C1’---C2’---...---C30’---D---...---X  develop
     \         
      C1---C2---...---C30                          develop-2
0
source

Source: https://habr.com/ru/post/1671367/


All Articles