How do I cancel a merge commit (non-squash)?

55 views Asked by At

enter image description here

In this case, if you output git log --online, you should see something like this

c6 merge iss53 to master
c5
c3
c4
c2
c1
...

As you can see, c4,c6 are commits from the master branch, and c5,c3 are commits from the iss53 branch

If we want to undo the merge, I would normally do something like this git reset --hard c4

But this is a bit inconvenient... I just want to undo the merge I just did, and I have to find the previous commit of the master branch in the merged logs of the two branches, as shown above (I have to find c4, not c5).
It's not hard, of course, but... I was wondering if there is a better way to do it.

And this is separate from the above question, I have 2 more questions.

1. if I don't do reset as above, and proceed with git reset --hard HEAD~, the merge is canceled fine.
But I'm confused, with the merge in place, isn't HEAD~ c4 and not c5? I thought it would be git reset --hard HEAD~ == git reset --hard c5, but it's not?

2. following on from the above question, what happens if I type git reset --hard c5?
I've tried it myself, but I'm a bit confused as to how it works.

0

There are 0 answers