Revert the first commit in a local git repository

Published on 09/14/2024

Let’s say we have init locally a new git repository and we have done the first commit. Immediately we discover that we have made a mistake.

How can we revert the first commit of a repository ?

If we try the command git reset HEAD~ we will obtain an error: the revision is unknown.

This is because there isn’t a previous commit to come back.

So the solution is to execute the commmand:

git update-ref -d HEAD

After run it the commit will be revert.

  • Article is published under CC-BY 4.0
  • If not explicitly declared code snippets are published under MIT license