git reset HEAD~1在这个git reset命令中〜1是什么意思?
我的印象是,〜1意味着:从HEAD开始,跟随1个链接,并将HEAD标记设置为新的提交节点。我期待
git reset HEAD~2
跟随2链接,然后设置HEAD标记。但是,如果我尝试了,我得到一个错误:
$ git reflog
c83bbda [email protected]{0}: reset: moving to HEAD~1
44c3540 [email protected]{1}: commit: you will be garbage soon
c83bbda [email protected]{2}: reset: moving to HEAD~1
aee7955 [email protected]{3}: commit: back to 4 lines
c83bbda [email protected]{4}: reset: moving to HEAD~1
19ec1d5 [email protected]{5}: commit: 3 lines
c83bbda [email protected]{6}: reset: moving to HEAD~1
a049538 [email protected]{7}: commit: added new line
c83bbda [email protected]{8}: commit (initial): first commit
$ git reset --hard HEAD~2
fatal: ambiguous argument 'HEAD~2': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
显然我错了,可是对于git的复位文档页面是不是在澄清这一非常有用的。那么,〜1是什么意思,为什么我需要它?
在这种特殊情况下,“未知版本”部分意味着'HEAD〜2 “根本不存在。 'HEAD'根据reflog提交'c83bbda',这是你的初始提交,所以它没有父母,'HEAD ^','HEAD〜1'等根本不存在。 – torek
请研究['gitrevisions(7)'手册](https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html),它解释了所有这些'〜'和'^'有趣的字符。 – kostix
可能重复[有什么区别〜和^在混帐](http://stackoverflow.com/questions/14733687/whats-the-difference-between-and-in-git) – kostix