git rebase --onto 分支后的 ~ 是什么意思?

What does the ~ mean after the branch of a git rebase --onto?

在 Git 文档为 git rebase --onto 给出的示例中,不清楚 ~ 的含义

A range of commits could also be removed with rebase. If we have the following situation:

enter code here E---F---G---H---I---J topicA

then the command

git rebase --onto topicA~5 topicA~3 topicA

would result in the removal of commits F and G:

E---H'---I'---J' topicA

This is useful if F and G were flawed in some way, or should not be part of topicA. Note that the argument to --onto and the parameter can be any valid commit-ish.

topicA~5 是指从 topicA 的头部开始的 5 次提交吗? (所以倒数?)

我想不出它还有什么意思,但我想在我的回购中尝试之前先确定一下。

本文来自git rev-parse

<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.

所以在你的情况下,是的,topicA~5 意味着从 topicA 的头部开始的 5 次提交:提交 E.

~ 表示提交的父项,因此 hash~5hash 的 grand-grand-grand-grand-parent。

图形上,可以这样看(输出类似于git log --graph --oneline,最旧的提交在底部):

* ggggg - (HEAD)
* fffff
* eeeee
* ddddd
* ccccc
* bbbbb
* aaaaa

然后:

ggggg~5 == bbbbb

我在这个回复中对~^做了更深入的解释: