Git undo merging 3 branches
I am not very familiar with Git. I have the basics down, but thats about it.
Anyway, my friend walked me through merging these 3 branches. He left me to run the mergetools part myself though. I didn't do the merge correctly, but had already pushed the changes. Is there some way I can undo my changes so it goes back to being 3 different branches, and then merge again?
edit*
Not 100% sure i开发者_如何转开发f it matters, but 2 of the branches are from upstream.
Find out the commit ID of the last clean state (i.e. the commit before the merge) for example with git log
and reset to that.
git reset --hard abcdef01
After that, force push your old state.
git push -f origin
Be aware: reset --hard
will discard unstaged changes, so be sure to have a clean working directory. Do a git stash
if not sure.
Additionally, this will only work without problems, if you didn't do any further work on the merged state, i.e. you didn't commit anything since then.
Man pages:
- git-reset
- git-stash
You may use git revert <>
, but there would be so many commits between the last clean commit and the current head
. I don't know much of the git commands, but there must be a way to print all the commits in between. You may write some script to extract only the SHAs and revert them all.
I am not 100% sure about this though. :)
精彩评论