2

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.

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

1

A fast-forward does not have a merge commit by definition: the only operation that has been performed is the relocation of your develop branch. Thus, you can use the following commands to revert that update:

git checkout develop                       # Go back to develop
git reset --hard develop@{1}               # Reset develop to its previous location
git push --force-with-lease origin develop # Push it, discarding the fast-forward

Then, if you want to force a merge commit event if it's empty, use the --no-ff flag:

git checkout develop
git merge --no-ff feature/<x>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.