GIT.WTF !?! Submit Article

How to revert pushed commit from repo?

Despite all the fixes you try, faulty commits do occasionally make it into the central repository. Still this is no reason to despair, since git offers an easy way to revert single or multiple commits:

Revert the commit with the specified id

git revert c761f5c

Revert the second to last commit

git revert HEAD^

Revert a whole range of commits

git revert develop~4..develop~2

In case you don’t want to create additional revert commits but only apply the necessary changes to your working tree, you can use the --no-commit/-n option.

# undo the last commit, but don't create a revert commit
git revert -n HEAD

The manual page at man 1 git-revert list further options and provides some additional examples.

Sign up below to receive updates, tips and more handy tutorials when git screws up. It’s good stuff & I don’t spam.