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.

  • Embedding a patch to a custom Linuxbrew formula
  • How can i git pull with overwriting changes
  • Maintaining git repo containing other cloned git repo
  • How do I import an existing GIT project into SVN, preserving GIT history on master branch?
  • Cloning through SSH makes the server think that GIT’s home directory is the root of the filesystem?
  • Push local Git branch to origin
  • 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.

    I run 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.

  • How to tell Git that it's the same directory, just a different name
  • What is a cleaner command to start a Git daemon?
  • Track branch after creation?
  • Local Git repository does not exist after sucessfull clone from cygwin bash
  • Why doesn't git diff work on the command line for me?
  • “Cannot spawn ssh” when connecting to Github, but ssh -T git@github.com works?
  • One Solution collect form web for “undoing accidental git merge without regressing history”

    Use 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.

    Git Baby is a git and github fan, let's start git clone.