1

Suppose following git history with mainline A and already merged branch B.

                  b1     b2
             -----•------•---            B
            /                \
   •------•----•--------------•-------•  A
   a1     a2   a3             a4      a5   

a4 is a merge commit w/ commit message merge "merge B into A.

Is it possible to to change the history into following.

                    b1'  b2'
   •-----•-----•-----•-----•-----•  A
   a1     a2   a3                a5  

edit: I don't want to change the commit date if possible.

1 Answers1

1

git cherry-pick saves commit's date

1) go to commit a2 git checkout a2
2) create new branch C git branch C
3) go to new branch C git checkout C
4) fetch from A branch git cherry-pick a3 b1 b2 a5
5) go back to A git checkout A
6) remove permanently everything newer than commit a2 git reset --hard a2
7) fetch from branch C git cherry-pick a3 b1 b2 a5
8) And good to remove branch C, remove branch C git branch -D C

robertbeb
  • 1,520
  • 1
  • 10
  • 13