为什么樱桃选秀后的重新组合不会应用两次相同的提交? [英] Why does a rebase after a cherry-pick not apply the same commit twice?
问题描述
例如:
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
首先,倒带头重放你的作品...
应用'C'
A --- B --- D'< - 主
\
\ ---- C'< - topic
这个魔法是如何工作的? IE浏览器。 git怎么知道它应该将C应用于D',而不是D到D'?解决方案
解答方案
git-rebase 的页面:
请注意,HEAD中的任何提交都会引入与HEAD ..中的提交相同的文本更改(例如,已经接受上传的补丁不同的提交消息或时间戳将被跳过)。
Rebase查看文本更改,并拒绝重放提交(如果它已存在)在分支上,你正在重新投入。
When you cherry pick a commit from one branch (say "topic") to another (lets call it "master") the history of that commit is rewritten, its hash changes and it effectively becomes a new, independent, commit.
However when you subsequently rebase topic against master git is clever enough to know not to apply to the commit twice.
Example:
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
How does this magic work? Ie. how does git know it should apply C to D', but not D to D'?
The answer is in the man page for 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 looks at the textual change, and refuses to replay that commit if it already exists on the branch you're rebasing onto.
这篇关于为什么樱桃选秀后的重新组合不会应用两次相同的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!