git - tilda 和 caret 符号对 git 中的 HEAD 有什么作用?
问题描述
我看到有些人使用带有 HEAD 的插入符号和 tilda 符号,例如 HEAD^ 或 HEAD~(NUMBER VALUE),我无法正确理解。
解决方案
从 rev-parse 文档:
<rev>^, e.g. HEAD^, v1.5.1^0
A suffix ^ to a revision parameter means the first parent of that commit object. ^<n> means the <n>th
parent (i.e. <rev>^ is equivalent to <rev>^1). As a special rule, <rev>^0 means the commit itself and
is used when <rev> is the object name of a tag object that refers to a commit object.
<rev>~<n>, e.g. master~3
A suffix ~<n> to a revision parameter means the commit object that is the <n>th generation ancestor of
the named commit object, following only the first parents. I.e. <rev>~3 is equivalent to <rev>^^^ which
is equivalent to <rev>^1^1^1. See below for an illustration of the usage of this form.