自动解决除部分文件外的git冲突问题 [英] Automatically resolve git conflicts except for some files

查看:262
本文介绍了自动解决除部分文件外的git冲突问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下git repo:

  oooooooooooooo 
oo
o V1 o V2
o
o MyChange

我有一个 git diff for V1..MyChange 。现在我想将所有内容合并到 V2 ,并为 V2..MyChange 创建一个新的差异。



如何让Git自动解决所有冲突,除了<$ c中存在的文件外,还可以通过取 V2 $ c> V1..MyChange 差异?



我曾尝试

<$ p $ git checkout MyChange
git merge V2

和I'如果文件修改和文件删除都会导致100次冲突。我只想从 V2 中取得所有内容,除了我感兴趣的文件 MyChange

解决方案

看起来你有几个补丁目前应用于 V1 之上,并且您想要更新您的回购并在 V2 之上应用您的修补程序。正如 @ Yehezkel的评论中所述, rebase 是一个更好的方法。



具体来说,您可以这样做:

  git checkout MyChange 
git rebase --onto V2 V1

或简单地说:

  git rebase --onto V2 V1 MyChange 



这会导致您的历史记录如下所示:

  oooooooooooooo 
oo
o V1 o V2
o
o MyChange

您可能仍然存在冲突,但应限制为实际冲突,即 V2 中和修补程序中已更改的文件。


I have the following git repo:

oooooooooooooo
   o       o
    o V1    o V2
     o
      o MyChange

I have a git diff for V1..MyChange . Now I would like to merge everything up to V2 and create a new diff for V2..MyChange.

How can I tell Git to auto resolve all conflicts by taking V2 except for the files present in V1..MyChange diff?

I have tried

git checkout MyChange
git merge V2

and I'm getting 100s of conflicts with both file modifications and file deletions. I just want to take everything from V2 except for the files I'm interested in MyChange.

解决方案

It looks like you have a couple patches that are currently applied on top of V1, and you want to update your repo and apply your patches on top of V2. As mentioned in @Yehezkel's comment, rebase is a better way to do this.

Specifically, you can do:

git checkout MyChange
git rebase --onto V2 V1

Or simply:

git rebase --onto V2 V1 MyChange

This will cause your history to look like this:

oooooooooooooo
   o       o
    o V1    o V2
             o
              o MyChange

You may still have conflicts, but it should be limited to actual conflicts, i.e. files that have changed both in V2 and in your patches.

这篇关于自动解决除部分文件外的git冲突问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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