Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Revert git merge without a merge commit

Tags:

git

git-merge

I branched a feature off develop. I made several commits on that feature branch. I then merged that feature branch back in develop & pushed everything to the origin.

I just noticed git did a fast forward which I didn't really want. Is it possible to revert that merge? In git log there is no commit for the merge (I wasn't asked for a comment either when I did it).

If it matters, nothing has changed since I pushed that merge.

like image 515
Lieuwe Avatar asked Nov 22 '25 03:11

Lieuwe


1 Answers

If you still have the feature branch you can do the following:

WARNING: You should only do the following if you are 100% sure that nothing changed on develop since commits that you want to remove.

  1. Find the SHA of the last commit on develop before the merge. (i.e. the state of develop before the merge)

  2. execute the following while you are on the develop branch:

    git reset --hard <sha-of-old-develop>
    
  3. execute

    git push -f
    

Now the repository should be back to how it was before you merged.

like image 155
Zavog Avatar answered Nov 24 '25 20:11

Zavog



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!