git rebase如何跳过上游已更改的提交? [英] How does `git rebase` skip the commit which its change already has in upstream?

查看:190
本文介绍了git rebase如何跳过上游已更改的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git-rebase文档说:

如果上游分支已经包含您所做的更改(例如,因为您邮寄了在上游应用的补丁程序),则该提交将被跳过.

If the upstream branch already contains a change you have made (e.g., because you mailed a patch which was applied upstream), then that commit will be skipped.

但是Git如何做到这一点?

But how does Git do that?

假定任何提交X是提交Y的父项,而diffXYgit diff X Y命令的结果.我有以下提交:

Assume any commit X is the parent of commit Y, and diffXY is the result of git diff X Y command. And I have following commits:

o---o---o        <- master
 \
  o---o---o---o  <- test <- HEAD

如果我执行git rebase master.然后我猜想Git通过跳过diffXYmaster中已经在test中的任何提交Ymaster中已经存在了跳过提交.

If I do a git rebase master. Then I guess Git does the skipping commit already have in master by skipping any commit Y in test that diffXY already have in master.

我已经运行了一些示例,它们就像我猜到的那样.

I've ran some examples and they were like what I guessed.

这只是我的猜测,对吗?

This is just my guess, am I right?

另外,在Git将test的提交重新提交到master之前,Git会执行此跳过任务吗?

Plus, does Git do this skipping task before Git do the reapplying test's commits onto the master?

推荐答案

git rebase 的第一个版本(2006年10月1.4.4)使用的是

这将检查从<since>可访问的所有补丁,但不能从<until>进行访问,并将它们与正在生成的补丁进行比较,所有匹配的补丁都将被忽略.

This will examine all patches reachable from <since> but not from <until> and compare them with the patches being generated, and any patch that matches is ignored.

因此它正在查看 提交9c6efa3 实现.

 if (ignore_if_in_upstream &&
    !get_patch_id(commit, &patch_id_opts, sha1) &&
     lookup_object(sha1))
     continue;

补丁ID"不过是与文件关联的文件差异的SHA-1之和. 补丁,忽略空格和行号.
因此,它合理地稳定",但同时也具有合理的唯一性,即,几乎两个具有相同补丁程序ID"的补丁程序几乎可以保证是同一件事.

A "patch ID" is nothing but a sum of SHA-1 of the file diffs associated with a patch, with whitespace and line numbers ignored.
As such, it's "reasonably stable", but at the same time also reasonably unique, i.e., two patches that have the same "patch ID" are almost guaranteed to be the same thing.

后来是委托给git rebase-am (Git 1.7.6,2月.2011)

That was later delegated to git rebase-am (Git 1.7.6, Feb. 2011)

然后提交b6266dc,Git 2.1.0,2014年7月使用了代替--ignore-if-in-upstream

使用git format-patch --ignore-if-in-upstream时,我们只能给出一个修订范围.
在下一次提交中,我们将要添加其他排除版本以正确处理派生点,因此将git-rebase--am转换为使用对称 与--cherry-pick --right-only的区别.

When using git format-patch --ignore-if-in-upstream we are only allowed to give a single revision range.
In the next commit we will want to add an additional exclusion revision in order to handle fork points correctly, so convert git-rebase--am to use a symmetric difference with --cherry-pick --right-only.

(在Git 2.18中进一步改进

(Further improved in Git 2.18)

这不会改变跳过相同提交"机制.

That does not change the "skip identical commit" mechanism.

这篇关于git rebase如何跳过上游已更改的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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