frans frans - 1 year ago 100
Git Question

git-svn undo a non-dcomitted merge

On a

checkout I accidentally merged a branch onto

git checkout -b my_branch
# make and commit changes
git checkout trunk
git svn rebase
git merge my_branch
# resolve conflicts

I did not
yet but to me it looks like now I've lost the original
and have a shuffled commit history:

$ tig
2016-09-19 15:09 other-dev o {trunk} remote changes
2016-09-19 15:01 me o changes on my_branch
2016-09-19 14:55 other-dev o remote changes
2016-09-19 14:33 me o changes on my_branch
2016-09-19 13:58 me o changes on my_branch
2016-09-19 13:44 other-dev o remote changes
2016-09-19 11:48 me o changes
2016-09-16 07:41 other-dev o changes

I now think bad things will happen if I try to
this state.

I'd like to 'undo' the whole merge, go back to
, rebase
and re-do the merge.

The only idea I come up with is to checkout
, delete
and re-branch

Is there an easier way to 'undo' a merge in this case?

Answer Source

I wonder why tig is not showing the merge actually. I tried to reproduce this and tig tries ordering the commits by date, even from different branches. But with the branch view it shows to me the branch like:

2016-09-20 13:31 me M─┐ [master] Merge branch 'foo'
2016-09-20 13:31 me o │ f
2016-09-20 13:30 me │ o [foo] e
2016-09-20 13:29 me o │ d
2016-09-20 13:28 me o │ c
2016-09-20 13:27 me │ o b
2016-09-20 13:17 me I─┘ a

and if I switch off branch view with 'G'

2016-09-20 13:31 me [master] Merge branch 'foo'
2016-09-20 13:31 me f
2016-09-20 13:30 me [foo] e
2016-09-20 13:29 me d
2016-09-20 13:28 me c
2016-09-20 13:27 me b
2016-09-20 13:17 me a

similar to yours, except that there are no o commit markers and the merge commit is shown.

Besides that, just look at the reflog of master with git reflog master to find the SHA of the master commit before your merge and then simply reset master to that commit with git reset --hard <good commit-ish> while having master checked out, or git branch -f master <good commit-ish> if you are not on master and don't want to check it out right now.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download