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

前端 未结 16 2209
醉酒成梦
醉酒成梦 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:26

    The difference between HEAD^ and HEAD~ is well described by the illustration (by Jon Loeliger) found on http://www.kernel.org/pub/software/scm/git/docs/git-rev-parse.html.

    This documentation can be a bit obscure to beginners so I've reproduced that illustration below:

    G   H   I   J
     \ /     \ /
      D   E   F
       \  |  / \
        \ | /   |
         \|/    |
          B     C
           \   /
            \ /
             A
    A =      = A^0
    B = A^   = A^1     = A~1
    C = A^2
    D = A^^  = A^1^1   = A~2
    E = B^2  = A^^2
    F = B^3  = A^^3
    G = A^^^ = A^1^1^1 = A~3
    H = D^2  = B^^2    = A^^^2  = A~2^2
    I = F^   = B^3^    = A^^3^
    J = F^2  = B^3^2   = A^^3^2
    

提交回复
热议问题