How to Undo Merge Git?

How to Undo Merge Git?

To undo a git merge, you need to find the commit ID of your last commit. Then, you need to use the git reset command to reset your repository to its state in that commit. There is no “git revert merge” command.

Can you undo a merge?

git revert will make sure that a new commit is created to revert the effects of that unwanted merge. This is in contrast to git reset , where we effectively "remove" a commit from the history. ... The -m 1 option tells Git that we want to keep the parent side of the merge (which is the branch we had merged into).

How do I undo last merge?

It can be done multiple ways.
  1. Abort Merge. If you are in-between a bad merge (mistakenly done with wrong branch), and wanted to avoid the merge to go back to the branch latest as below: git merge --abort.
  2. Reset HEAD to remote branch. ...
  3. Delete current branch, and checkout again from the remote repository.
Sarah Jenkins
Author

Sarah Jenkins

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.