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

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

    TLDR

    ~ is what you want most of the time, it references past commits to the current branch

    ^ references parents (git-merge creates a 2nd parent or more)

    A~ is always the same as A^
    A~~ is always the same as A^^, and so on
    A~2 is not the same as A^2 however,
    because ~2 is shorthand for ~~
    while ^2 is not shorthand for anything, it means the 2nd parent

提交回复
热议问题