What does the caret (^) character mean?

I saw an answer to a question here that helps restore a deleted file in git.

The solution was

git checkout <deleting_commit>^ -- <deleted_file_path>

What does the caret character ( ^ ) do? I've seen it elsewhere doing very useful things in git. It's magical. Someone please spoil it for me and tell me what it does?


HEAD^ means the first parent of the tip of the current branch.

Remember that git commits can have more than one parent. HEAD^ is short for HEAD^1 , and you can also address HEAD^2 and so on as appropriate.

You can get to parents of any commit, not just HEAD . You can also move back through generations: for example, master~2 means the grandparent of the tip of the master branch, favoring the first parent in cases of ambiguity. These specifiers can be chained arbitrarily , eg, topic~3^2 .

For the full details, see the “Specifying Revisions” section of git rev-parse --help .


It means "parent of". So HEAD^ means "the parent of the current HEAD". You can even chain them together: HEAD^^ means "the parent of the parent of the current HEAD" (ie, the grandparent of the current HEAD), HEAD^^^ means "the parent of the parent of the parent of the current HEAD", and so forth.


The caret refers to the parent of a particular commit. Eg HEAD^ refers to the parent of the current HEAD commmit. (also, HEAD^^ refers to the grandparent).

链接地址: http://www.djcxy.com/p/18944.html

上一篇: 恢复Git仓库中已删除的文件夹

下一篇: 脱字符(^)字符是什么意思?