undoing accidental git merge without regressing history
I did something stupid and accidently merged a topic branch into my master branch and then pushed it live to github (where others have pulled). Just to make sure it was a completely moronic mistake, I pulled it out to my production servers.
I’ve hung my head in shame for the appropriate amount of time and now I need to figure out how to effectively roll back the code commits while progressing the commit history.
To get my production code to the correct checkout, I ran
git checkout hashoflettersandnumbers and that’s the commit I want the production HEAD to be.
git reset hashoflettersandnumbers and then git clean to remove the changes from that commit going forward, but I can’t seem to get that code to be the HEAD of the master branch and make a fresh commit.
One Solution collect form web for “undoing accidental git merge without regressing history”
git revert on each of the branches. This will create a new commit that preserves your mistake for all eternity, but gives you back the same tree as you had before you merged.
For example, if 123456 is the merge commit…
$ git checkout master $ git revert 123456 $ git checkout topic-branch $ git revert 123456
This assumes that this wasn’t a “fast-forward” merge.