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