如何使Git合并操作忽略对两个分支所做的相同更改? [英] How to make a Git merge operation ignore identical changes made to both branches?

查看:86
本文介绍了如何使Git合并操作忽略对两个分支所做的相同更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我们有一个开发分支"A",以及两个子分支"B1"和"B2"(均取自A).假设您在B1和B2中的整个项目上运行了 format代码命令(在我们的示例中为ReSharper的清理代码).

Lets assume that we have one development branch 'A', and two sub branches 'B1' and 'B2', (both taken from A). Lets say that you run a format code command (in our case ReSharper's cleanup code) on the entire project in B1 and B2.

现在,当我们尝试将B2合并为B1时,Git将报告项目中所有文件上的冲突(在我们的案例中很多).当仔细观察每个冲突时,即使B1和B2(?)进行了完全相同的更改,Git似乎也认为存在冲突.

Now, when we try to merge B2 into B1, Git will report conflicts on all files in the project (quite a large number in our case). When looking closer at each conflict, it seems like Git thinks theres a conflict even though the exact same change was made in both B1 and B2(?)

如果B1和B2中的文件完全相同,有没有一种方法,自定义的驱动程序/git属性等可以使Git合并操作不报告冲突?

Is there a way, custom driver/git attribute etc that will make a Git merge operation not report a conflict if the files in B1 and B2 are exactly the same?

也许我弄错了,也许是空格/行尾问题(例如B1和B2中不同的行尾),在这种情况下,我可以在堆栈溢出的地方找到解决方案.

Maybe I've got it wrong, maybe it is a whitespace/line ending issue (eg different line endings in B1 and B2) in which case I can find the solution here on stack overflow.

推荐答案

昨天,在从一个分支分支(和分支分支)中进行大量的选择之后,我遇到了类似的问题,之后我又与主分支合并了.具有相同更改的许多冲突.我通过合并策略解决了这个问题:

Yesterday I had similar issue after a lot of cherry-pick from (and to) a side branch where I after merged with my main branch. A lot of conflicts with identical change. I solved this with a merge strategy:

git checkout main-branch
merge --no-commit -s recursive -X ours side-branch

您可以将我们的"更改为他们的".请小心,因为所有冲突都会自动选择我们的"或他们的"一方解决.就我而言,由于这个原因我几乎没有合并错误,因此我手动进行了修复.在此处查看其他有趣的合并策略选项: https://www.kernel.org/pub/software/scm/git/docs/git-merge.html

you can change "ours" to "theirs". Be careful because all conflicts are automatically solved choosing "ours" or "theirs" side. In my case I had few mis-merges due to this, and I fixed manually. See others interesting options of merge strategies here: https://www.kernel.org/pub/software/scm/git/docs/git-merge.html

您也可以尝试使用重新设置(在我的情况下,由于分支差异太大,并且每次新的重新设置交互都发生新冲突,因此无法正常工作).请参阅: http ://davitenio.wordpress.com/2008/09/27/git-merge-after-git-cherry-pick-avoiding-duplicate-commits/

You can also try to use a rebase (in my case it did not work well because the branchs were too different and I had a new conflict in each new rebase interaction). See this: http://davitenio.wordpress.com/2008/09/27/git-merge-after-git-cherry-pick-avoiding-duplicate-commits/

这篇关于如何使Git合并操作忽略对两个分支所做的相同更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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