当您从一个分支(比如“主题”)挑选一个提交到另一个分支(我们称之为“主”)时,该提交的历史记录被重写,它的哈希值发生变化,它实际上变成了一个新的、独立的提交。
然而,当您随后根据主 git 对主题进行 rebase 时,git 足够聪明,知道不要对提交应用两次。
例子:
A --- B <- master
\
\---- C ---- D <- topic
$ git checkout master
$ git cherrypick D
A --- B --- D' <- master
\
\---- C ---- D <- topic
$ git checkout topic
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying 'C'
A --- B --- D' <- master
\
\---- C' <- topic
这个魔法是如何运作的? IE。 git 如何知道它应该将 C 应用到 D',而不是 D 应用到 D'?
最佳答案
答案在 git-rebase 的手册页中:
Note that any commits in HEAD which introduce the same textual changes as a commit in HEAD.. are omitted (i.e., a patch already accepted upstream with a different commit message or timestamp will be skipped).
Rebase 查看文本更改,如果该提交已经存在于您要进行 rebase 的分支上,则拒绝重放该提交。
关于git - 为什么 cherry-pick 之后的 rebase 不会两次应用相同的提交?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14509878/