git rebase如何跳过上游已更改的提交?

编程入门 行业动态 更新时间:2024-10-27 15:29:16
本文介绍了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的父项,而diffXY是git 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通过跳过diffXY在master中已经在test中的任何提交Y在master中已经存在了跳过提交.

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)使用的是 git format --ignore-if-in-upstream

这将检查从<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.

因此它正在查看 补丁ID :请参见提交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如何跳过上游已更改的提交?

本文发布于:2023-11-24 10:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624783.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:跳过   git   rebase

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!