0

Initially, I branched from master (A) and made a commit (B) on my feature branch...then merged in changes from master (C as D) and made another commit (E) using the changes from that merge:

-A--C
 \  \
  B--D--E

Now, I'd like to eliminate the merge commit itself (D) and clean up my branch's history by rebasing my entire branch against a later master (C):

-A--C
    \
    B--E

However, I am sufficiently confused about how to accomplish this.

EvanK
  • 1,052
  • 1
  • 10
  • 23
  • 1
    Did you try `git rebase C E`? – mkrieger1 May 04 '20 at 16:48
  • @mkrieger1 I have, but it leaves me in a `HEAD detached` state – EvanK May 04 '20 at 16:55
  • 1
    For `E` you need to use the branch name. Or you manually set the branch pointer to the new `E` commit afterwards. – mkrieger1 May 04 '20 at 17:02
  • Does this answer your question? [How to restore linear git history after nonlinear merge?](https://stackoverflow.com/questions/57328341/how-to-restore-linear-git-history-after-nonlinear-merge) – mkrieger1 May 05 '20 at 08:50

1 Answers1

1

the "by hand" approach would be:

git checkout --detach C
git cherry-pick B
git cherry-pick E

Then you can set a branch over here:

git branch -f some-branch
git checkout some-branch
eftshift0
  • 26,375
  • 3
  • 36
  • 60
  • Or replace the first command by `git checkout -b some-branch C`, then the last two commands are not necessary. – mkrieger1 May 04 '20 at 17:03