What's the difference between HEAD^ and HEAD~ in Git?

前端 未结 16 2067
醉酒成梦
醉酒成梦 2020-11-22 10:43

When I specify an ancestor commit object in Git, I\'m confused between HEAD^ and HEAD~.

Both have a \"numbered\" version like HEAD^3<

16条回答
  •  深忆病人
    2020-11-22 11:29

    Both ~ and ^ on their own refer to the parent of the commit (~~ and ^^ both refer to the grandparent commit, etc.) But they differ in meaning when they are used with numbers:

    • ~2 means up two levels in the hierarchy, via the first parent if a commit has more than one parent

    • ^2 means the second parent where a commit has more than one parent (i.e. because it's a merge)

    These can be combined, so HEAD~2^3 means HEAD's grandparent commit's third parent commit.

提交回复
热议问题