为什么樱桃选秀后的重新组合不会应用两次相同的提交? [英] Why does a rebase after a cherry-pick not apply the same commit twice?

查看:138
本文介绍了为什么樱桃选秀后的重新组合不会应用两次相同的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当你从一个分支选择一个提交(称为主题)到另一个(我们称之为主)时,该提交的历史被重写,它的哈希变化并且它实际上成为一个新的,独立的提交。然而,当你随后对主master进行rebase主题足够聪明,知道不应用于提交两次。



例如:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆