What does the caret (^) character mean?

前端 未结 8 905
广开言路
广开言路 2020-11-29 17:24

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

The solution was

git checkout ^ -- 

        
相关标签:
8条回答
  • 2020-11-29 18:23

    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 , e.g., topic~3^2. See related answer to What’s the difference between HEAD^ and HEAD~ in Git?

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

    0 讨论(0)
  • 2020-11-29 18:24

    The (^) gets the parent source of the command i.e. HEAD^ will get the parent of HEAD.

    0 讨论(0)
提交回复
热议问题