3

I had some local commits and there were changes made on master. So I did a:

 git pull // it automatically merged and had a conflict with one file only.
 subl <file> // Made the wrong fix and saved it
 git commit // It opened nano and I Typed "fixed merge" saved it 
 git push master origin

How do I go back to before the pull and redo the merge and push? Especially get back to right before the merge.

Robin Green
  • 32,079
  • 16
  • 104
  • 187
IskandarG
  • 323
  • 1
  • 3
  • 9
  • Possible duplicate of [How to revert a merge commit that's already pushed to remote branch?](http://stackoverflow.com/questions/7099833/how-to-revert-a-merge-commit-thats-already-pushed-to-remote-branch) – 1615903 Nov 02 '16 at 08:43
  • There are more detailed instructions on undoing merges here: [Undoing mergers](https://git-scm.com/blog/2010/03/02/undoing-merges.html) – 108 Nov 02 '16 at 08:47

2 Answers2

6

You can revert that merge with:

git revert -m 1 (Commit id of the merge commit)

More informations can be found in Official GUIDE

And you can do it in other way by using git reflog <branch> to find out where your branch was before the merge, and git reset --hard <commit_id> to restore the old revision (you will get back to this commit). Then just you can push it back.

Reflog will show you older states of the branch, so you can return it to any change set you like.

Make sure you are in correct branch

Karol Gasienica
  • 2,825
  • 24
  • 36
  • So after I do this and do a pull will I get the same conflict I got before? And I see that the push i made with the wrong merge is still on master ? – IskandarG Nov 02 '16 at 08:57
  • 3
    This leaves Git with the erroneous belief that the merged commits are still on the target branch. – Karol Gasienica Nov 02 '16 at 09:22
0

You can revert to the last commit:

git revert HEAD

It will revert your commit as a new commit