简体   繁体   English

Git合并并解决当前分支的任何冲突

[英]Git merge and resolve any conflicts to current branch

So I have my master branch, along with branch 'bob'. 所以我有我的主分支,以及分支'bob'。

I've made many changes in both and now I want merge master into bob to keep him updated. 我在两者中做了很多改动,现在我想将合并大师变成bob以便让他更新。 The only thing is, if there is a conflict I want it to automatically resolve to bob. 唯一的问题是,如果存在冲突,我希望它能自动解析为bob。

I've been recommended the following: 我被推荐如下:

git checkout bob
git merge master -s ours

This does not work because I don't even get the changes from master that don't conflict. 这不起作用,因为我甚至没有从master中获得不冲突的更改。

please help! 请帮忙!

First, you need to merge all changes from master to bob: 首先,您需要将所有更改从master合并到bob:

  • all modification from master must be added to bob if there is no conflict 如果没有冲突,必须将所有来自master的修改添加到bob中
  • any conflict must be solved by keeping content of bob branch. 必须通过保留bob分支的内容来解决任何冲突。

The question " How do I tell git to always select my local version for conflicted merges on a specific file? " explains how to do that, with a merge driver. 问题“ 如何告诉git总是选择我的本地版本来解决特定文件上的冲突? ”解释了如何使用合并驱动程序。

Once the merge has been done, a simple: 合并完成后,一个简单的:

 git checkout master
 git rebase bob

allows for the HEAD of master to fast-forward to the one of bob. 允许主人的HEAD快进到bob之一。 Master will go on from there from the content of bob. 师父将从那里继续鲍勃的内容。

I see the gap with the ours merge strategy. 我看到了与我们的合并策略的差距。 If integrating your own merge driver is too much, and if you like Emacs, consider using ediff as your "merge tool". 如果集成自己的合并驱动程序太多,并且如果您喜欢Emacs,请考虑使用ediff作为“合并工具”。 You can tell it to "prefer" your contributions in conflicts. 你可以告诉它“更喜欢”你在冲突中的贡献。 That in addition to having it focus only on conflicting changes allows you to review the merge result before committing, just to make sure that taking only your contributions still result in a coherent file. 除了让它只关注冲突的更改之外,您还可以在提交之前查看合并结果,以确保仅获取您的贡献仍然会产生一致的文件。

Unfortunately, ediff has yet to be integrated as a supported merge tool. 遗憾的是, ediff尚未作为受支持的合并工具集成。 This thread on the git mailing list from June 2007 describes some of the integration problems. 2007年6月git邮件列表上的这个帖子描述了一些集成问题。 Here 's another. 是另一个。

Git does ship with built-in support for emerge , another Emacs merging mode, but I far prefer ediff . Git确实附带了emerge的内置支持,另一种是Emacs合并模式,但我更喜欢ediff

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM