0

I merged a branch in dev using vscode: git merge branch1

I want to unmerge this branch1 from dev and have the original code that was in dev before merging the branch.

I tried pulling the dev branch's code again: git pull origin dev. But I got notification that branch is already-upto-date.

So can I unmerge the branch. Also, I have not committed the merged branch into dev. So original code of dev is still there in git.

Siva Pradhan
  • 791
  • 1
  • 6
  • 23
  • Did you push to the remote after making the erroneous unwanted merge? – Tim Biegeleisen Apr 11 '21 at 07:28
  • `git reset --hard HEAD^` will probably do the trick. It means “reset this branch to the state it was one commit ago (the ^ can be put multiple times to go back multiple steps). If you want to then push it to a remote you’ll have to possibly force it. But be careful with reset, especially with hard since you can lose things (or at least make it difficult to get them back) – Sami Kuhmonen Apr 11 '21 at 07:28
  • @TimBiegeleisen no I have not pushed to the remote. – Siva Pradhan Apr 11 '21 at 07:29
  • @SamiKuhmonen Actually I have not pushed anything into dev. I have just merged the code locally. So code in original code in dev in git is still there. – Siva Pradhan Apr 11 '21 at 07:31
  • 1
    @SamiKuhmonen Actually, it would be better to hard reset to the exact hash of the prior commit. Reason being, a merge commit has 2 parents, so I'm not sure that `HEAD^` would always be correct here. – Tim Biegeleisen Apr 11 '21 at 07:32

0 Answers0