1

I had a local branch that was older, so I wanted to update it with changes from the remote master while keeping the local changes I had made to it.

So I did this:

git checkout master

git pull master

git checkout my_local_branch

git merge master

This ruined my local branch and made it basically just a clone of master.

Luckily(I think?) I never committed it or pushed it to origin.

So I want to undo the merge.

But I tried , git merge --abort and it tells me:

fatal: There is no merge to abort (MERGE_HEAD missing).

Also the history is all different because basically it looks just like master.

Is there a way to fix my local branch so that it reverts back to what it looked like before I merged it with master?

Here is what git reflog shows:

51f03ce5 (HEAD -> my_local_branch, origin/master, origin/HEAD, master) HEAD@{0}: merge master: Fast-forward
4b2e85a3 HEAD@{1}: checkout: moving from master to my_local_branch
51f03ce5 (HEAD -> my_local_branch, origin/master, origin/HEAD, master) HEAD@{2}: pull: Fast-forward
949c9d1f HEAD@{3}: checkout: moving from my_local_branch to master

Thanks!

SkyeBoniwell
  • 6,345
  • 12
  • 81
  • 185
  • 3
    Short answer : if the merge was a simple fast-forward, you're not "in merging" any more, the merge is done so it can't be aborted. Check your reflog with `git reflog` to search for the previous position (commit hash) for your branch. Then you'll just need to reset to that. – Romain Valeri Mar 10 '21 at 16:34
  • 2
    (Alternatively, if your branch has been pushed before the bad merge, it might be easier to reset to it.) – Romain Valeri Mar 10 '21 at 16:36
  • @RomainValeri I haven't pushed anything. This was always a local branch. I updated my question to show what `git reflog` shows..I'm not sure what it means – SkyeBoniwell Mar 10 '21 at 17:15
  • 2
    Seems you're looking for `4b2e85a3` here. Before resetting your branch, maybe first create a branch and check that it's what you wanted to recover with `git checkout -b recovery_branch 4b2e85a3`. If you're OK with it, just make your branch point there with (from your branch) `git reset --hard recovery_branch` – Romain Valeri Mar 10 '21 at 17:22

0 Answers0