HEAD~ vs HEAD^ vs HEAD@{} also known as tilde vs caret vs at sign

后端 未结 3 896
忘掉有多难
忘掉有多难 2020-11-28 02:01

HEAD is a pointer at the current branch. I have seen a variety of notations for ancestors of HEAD including

  • HEAD~2
  • HEAD^2
3条回答
  •  -上瘾入骨i
    2020-11-28 02:56

    git reference suffixes (^N, ~N, @{...})

    ref~ is shorthand for ref~1 and means the commit's first parent. ref~2 means the commit's first parent's first parent. ref~3 means the commit's first parent's first parent's first parent. And so on.

    ref^ is shorthand for ref^1 and means the commit's first parent. But where the two differ is that ref^2 means the commit's second parent (remember, commits can have two parents when they are a merge).

    The ^ and ~ operators can be combined.

    Here's a diagram showing how to reference various commits using HEAD as the starting point.

    src

提交回复
热议问题