Skip to content

Instantly share code, notes, and snippets.

@JonathanGawrych
Created April 7, 2023 16:43
Show Gist options
  • Save JonathanGawrych/45143e71c711b162131d13e2a0786517 to your computer and use it in GitHub Desktop.
Save JonathanGawrych/45143e71c711b162131d13e2a0786517 to your computer and use it in GitHub Desktop.
How to undo a git merge

Figured out how to undo merge commits. If you have a branch like so:

develop -A--B--C--D--E
             \     \
topic         1--2--M--3

And you wanted to remove the merge, checkout topic and run git rebase --onto 2 M, where M is the merge commit and 2 is the topic's commit before the merge commit: WARNING: THIS DELETES EVIL MERGE CHANGES (changes that do not appear in either parent)

develop -A--B--C--D--E
             \
topic         1--2--3'

After than you could then run git rebase develop and you'd get:

develop -A--B--C--D--E
                      \
topic                  1'--2'--3''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment