0

As very new with git, I need help to probably very basic issue I am having.

I did following

  1. I am on develop branch and I did git fetch origin and git merge origin/develop
  2. The merge was successful

But for whatever reason, I decide I did not want to do git fetch/merge I did above, so I would like to remove it and go to where I was before I did step 1 above.

How do I do that?

cd491415
  • 823
  • 2
  • 14
  • 33
  • Possible duplicate of [Undo a Git merge that hasn't been pushed yet](https://stackoverflow.com/questions/2389361/undo-a-git-merge-that-hasnt-been-pushed-yet) – phd Nov 07 '18 at 19:54
  • https://stackoverflow.com/search?q=%5Bgit%5D+undo+merge – phd Nov 07 '18 at 19:54

2 Answers2

1

So essentially what you want to do is undo the merge with origin. You can do that by performing git reset --hard followed by hash of the state prior to merge. You can find the hash by doing git reflog

So full command would look something like this.

git reset --hard a76f5d5

Careful though, as git reset --hard will remove all uncommitted changes!

ibrcic
  • 756
  • 1
  • 6
  • 12
  • The changes I did on my own branch are already committed (I did add and commit). Then I switched to develop branch and did git fetch/merge to get latest remote changed. But for some reason, I see as a result of git fetch/merge (no conflicts) lots of files now showing by git status as being untracked, not staged, or not committed. So, I am bit hasitant and want to revert my latest git fetch/merge and try doing it again. – cd491415 Nov 07 '18 at 19:53
  • Don't worry if it is on another branch, it won't change any of that. But, just to be sure, you can always backup current state by ziping the whole project folder. Just make sure that you are on develop branch when doing the reset. Also, as someone else said, use git pull, it's essentially doing the fetch + merge in one step. – ibrcic Nov 07 '18 at 19:59
1

if you have nothing pending on your working tree and you don't want to have a new revision to revert the merge, you can git reset --hard to the revision where you were before.... then it's like the merge never happened.

git reset --hard old-revision-where-I-was-before-merge

Also, git pull does a merge, no need to merge after pull.

eftshift0
  • 26,375
  • 3
  • 36
  • 60