在合并过程中,如何选择一个分支中的文件? [英] How to prefer files from one branch during a merge?

查看:182
本文介绍了在合并过程中,如何选择一个分支中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前一段时间,我从master分支创建了一个分支.我们称之为new_feature.当我在new_feature上工作时,master分支遵循其正常演变.现在new_feature准备好要合并到master中,我看到了一些冲突,所有这些冲突都进入了与实际新功能完全无关的文件中(例如某些配置文件以及在master上更改过的类似文件) .我将手动解决冲突,但我想知道,因为这种情况经常发生,如何将new_feature分支合并到master中,同时始终保留文件的master版本,以防万一冲突?

我确定它很简单,并且与诸如保持版本"之类的东西有关,但是由于它是一个非常敏感的主题,所以我宁愿问而不是后悔.

解决方案

如注释中所述,文档中有几种策略.您也可以在这里找到它们: http://git-scm.com/docs/git-merge

您正在寻找git merge -s recursive -X oursgit merge -s recursive -X theirs,具体取决于您所在的分支.请特别注意这些内容,因为您可能会意外错过其他分支对文件的更改,这些更改将被覆盖.

由于控制力强,我更喜欢的另一种方法是git checkout <other-branch> -- <list of files>.这样,我就不会意外地覆盖了错误更改的文件.

Some time ago I created a branch from my master branch. Let's call it new_feature. While I was working on new_feature, the master branch followed its normal evolution. Now that new_feature is ready to be merged into master I see some conflicts, all of them are into files that are totally unrelated to the actual new feature (like some config files and the likes that have changed on master). I'm going to solve the conflicts manually but I was wondering, since it's a situation that happens quite often, how I could just merge the new_feature branch into master while always keeping the master version of the files in case of conflict?

I'm sure it's easy and is related to something like 'keep version' but since it's a pretty sensitive subject I'd rather ask than be sorry.

解决方案

As mention in the comment there are several strategies in the documentation. You can also find them here: http://git-scm.com/docs/git-merge

You are looking for either git merge -s recursive -X ours or git merge -s recursive -X theirs depending on the branch that you are on. Be careful with these as you can accidentally miss changes to your files from the other branch and these would be overwritten.

Another method, which I prefer due to more control, is to git checkout <other-branch> -- <list of files>. This way I don't accidentally overwrite a file with the wrong changes.

这篇关于在合并过程中,如何选择一个分支中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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