Rafael Reis
Rafael Reis

Reputation: 610

Git - Unmerge after other commits have been made

The image illustrates my merge history, including a merge that I had done prior to several more recent commits. Can I undo this merge, while keeping the commits that I have done after? I merged with develop when I should have merged with master.

enter image description here

Upvotes: 2

Views: 112

Answers (3)

Martin G
Martin G

Reputation: 18129

You can try

git revert -m 1 <sha1>

where <sha1> is the merge commit you want to get rid of.

Described here: https://mijingo.com/blog/reverting-a-git-merge

Upvotes: 1

David C.
David C.

Reputation: 1994

In theory, you could first run git log to get a list of commits. Then, you would run git checkout to a different branch (if you don't have one, use git branch <branch name> to create. Finally, run git reset --hard <commit ID for your commit of interest>. This will permanently undo your merge commit since the point you choose.

Upvotes: 1

tehp
tehp

Reputation: 6434

This kind of thing is covered here.

You will likely need to revert and merge depending on your situation.

Upvotes: 1

Related Questions