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?
While there is no undo git init command, you can undo its effects by removing the . git/ folder from a project. You should only do this if you are confident in erasing the history of your repository that you have on your local machine.
You can delete the HEAD and restore your repository to a new state, where you can create a new initial commit:
git update-ref -d HEAD
After you create a new commit, if you have already pushed to remote, you will need to force it to the remote in order to overwrite the previous initial commit:
git push --force origin
You just need to delete the branch you are on. You can't 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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With