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

后端 未结 3 903
忘掉有多难
忘掉有多难 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条回答
  •  日久生厌
    2020-11-28 03:01

    From the docs here.

    • HEAD~2 : 2 commits older than HEAD
    • HEAD^2 : the second parent of HEAD, if HEAD was a merge, otherwise illegal
    • HEAD@{2} : refers to the 3rd listing in the overview of git reflog
    • HEAD~~ : 2 commits older than HEAD
    • HEAD^^ : 2 commits older than HEAD

    If HEAD was a merge, then

    • first parent is the branch into which we merged,
    • second parent is the branch we merged.

    Some Combinations and Synonyms

    First Parent    First Grandparent    Second Parent    Second Grandparent
    
    HEAD~
    HEAD^
    HEAD~1          HEAD~2               HEAD^2           HEAD^2~        
    HEAD^1          HEAD^^                                HEAD^2^ 
    

提交回复
热议问题