suheb
suheb

Reputation: 1629

Squash merge commit

I have pull request on github to which I pushed some commits. It's been idle for some time and now it has merge conflicts. So I merged my feature branch with the master branch, resolved the conflicts and pushed it. Now I want to squash/remove the merge commit that has been created. I tried git rebase -i but there are some commits between my last commit and the merge commit. Any help is appreciated.

Upvotes: 0

Views: 641

Answers (1)

user3159253
user3159253

Reputation: 17455

I think that you're on the right track, and now have 2 options Look at the picture:

A1 — A2 — A3 — A4
 \
  F1 — F2 — F3

where A1..A4 is the mainline of the project and F1..F3 is your feature branch submitted in the PR. Now however F3 can't be easily merged with A4 due to conflicting changes.

You could create merging commit F4:

A1 — A2 — A3 — A4
 \              \
  F1 — F2 — F3 — F4

and then submit F4 as PR. In this case the repo owner could take F4 and merge it to the mainline, so the project history will look like this:

A1 — A2 — A3 — A4 — A5 
 \              \ /
  F1 — F2 — F3 — F4

Essentially, A5 sourcetree will be equal to F4 and in some workflows A5 is exactly F4.

Alternatively, you could checkout F3 (git checkout <feature_branch>; git reset --hard F3;) and then use git rebase -i A4 to reapply changes from your feature branch over the current project HEAD. You need to resolve all the conflicts one by one and in the end you'll get the following commits structure:

A1 — A2 — A3 — A4
                 \
                  F1' — F2' — F3'

and then you may forcibly update your repository fork with git push -f ... and then re-new the PR.

Upvotes: 1

Related Questions