如何恢复初始git提交? [英] How to revert initial git commit?
问题描述
我第一次提交git仓库;然后我对这个承诺感到后悔,并希望恢复它。我尝试
#git reset --hard HEAD〜1
$ p
我收到以下消息:
fatal:ambiguous argument'HEAD〜 1':未知的版本或路径不在工作树中。
此提交是存储库的第一次提交。任何想法如何撤消git的初始提交?
解决方案你只需要删除你所在的分支。你不能使用
git branch -D
,因为这样做有安全检查。您可以使用update-ref
来做到这一点。git update- ref -d HEAD
不使用
rm -rf .git
或类似的东西,因为这将彻底清除包括所有其他分支以及您尝试重置的分支在内的整个存储库。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?
解决方案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 useupdate-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.这篇关于如何恢复初始git提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!