git 应用补丁时有没有办法解决冲突?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16190387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:01:55  来源:igfitidea点击:

When applying a patch is there any way to resolve conflicts?

gitgit-amgit-apply

提问by Kenoyer130

I am on windows.

我在窗户上。

For various reasons we have multiple git instances of different svn branches.

由于各种原因,我们有多个不同 svn 分支的 git 实例。

Many times I want to fix an issue in repository A, generate a patch, and apply it to repository B. This works fine except if there are conflicts.

很多时候我想修复存储库 A 中的问题,生成补丁,然后将其应用到存储库 B。除非存在冲突,否则这很好用。

When rebasing I just right click the folder and use tortioseGit and select the resolve option. This brings up a nice gui to let me work through my conflicts.

重新定位时,我只需右键单击该文件夹并使用 tortioseGit 并选择解析选项。这带来了一个很好的 gui 来让我解决我的冲突。

Is there any way to accomplish this with rejected patch chunks?

有没有办法用被拒绝的补丁块来完成这个?

Here is my current approach to creating/applying the patches

这是我目前创建/应用补丁的方法

git format-patch master --stdout > c:\patch\file.patch
git apply --reject --ignore-space-change --ignore-whitespace c:\patch\file.patch

回答by g19fanatic

To generate your patch do the following:

要生成补丁,请执行以下操作:

git format-patch --stdout first_commit^..last_commit > changes.patch

Now when you are ready to apply the patches:

现在,当您准备好应用补丁时:

git am -3 < changes.patch

the -3will do a three-way merge if there are conflicts. At this point you can do a git mergetoolif you want to go to a gui or just manually merge the files using vim (the standard <<<<<<, ||||||, >>>>>>conflict resolution).

-3如果存在冲突,将进行三向合并。此时,git mergetool如果您想转到 gui 或只是使用 vim(标准的<<<<<<, ||||||,>>>>>>冲突解决方案)手动合并文件,您可以执行 a 。

回答by mplf

If you are frequently running into the same conflict set when applying patches, rebasing or merging then you can use git rerere (reuse recorded resolution) function. This allows you to pre-define how conflicts should be resolved based on how you resolved them in the past. See http://git-scm.com/blog/2010/03/08/rerere.htmlfor details of how this works.

如果您在应用补丁、变基或合并时经常遇到相同的冲突集,那么您可以使用 git rerere(重用记录的解决方案)功能。这允许您根据过去解决冲突的方式预先定义应如何解决冲突。有关其工作原理的详细信息,请参阅http://git-scm.com/blog/2010/03/08/rerere.html

回答by ams

TortoiseGit has a merge feature that can open patch files.

TortoiseGit 有一个合并功能,可以打开补丁文件。

There's a picture of it here.

有它的照片在这里

回答by MichiBack

My approach is:

我的做法是:

  • Create an "Integration"-Branch where the files are identical
  • Apply the patch to this Integration-Branch
  • Merge or rebase it to master (don't know if rebase is useful here, because I don't know what will happen when applying further patches)
  • 创建一个“集成”-分支,其中文件相同
  • 将补丁应用到这个集成分支
  • 合并或者rebase到master(不知道rebase在这里有没有用,因为不知道再打补丁会怎么样)