Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.4k points)

I commit to a git repository for the first time; I then regret the commit and want to revert it. I try

# git reset --hard HEAD~1

I get this message:

fatal: ambiguous argument 'HEAD~1': unknown revision or path not in the working tree.

This commit is the first commit of the repository. Any idea how to undo git's initial commit?

1 Answer

0 votes
by (27.5k points)

First of all you need to delete the branch you are on. You cannot use git branch -D as this has a safety check against doing this. You can use update-ref to do this.

$ git update-ref -d HEAD

Remember that do not use rm -rf .git or anything like this as this will completely wipe your entire repository including all other branches as well as the branch that you are trying to reset.

Browse Categories

...