开发者

Git merge and resolve any conflicts to current branch

So I have my master branch, along with branch 'bob'.

I've made many changes in both and now I want merge master into bob to keep him updated. The only thing is, if there is a conflict I want it to automatically resolve to bob.

I've been recommended the following:

git checkout bob
git merge master -s ours

This does not w开发者_运维知识库ork because I don't even get the changes from master that don't conflict.

please help!


First, you need to merge all changes from master to bob:

  • all modification from master must be added to bob if there is no conflict
  • any conflict must be solved by keeping content of bob branch.

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.

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. 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". 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. This thread on the git mailing list from June 2007 describes some of the integration problems. Here's another.

Git does ship with built-in support for emerge, another Emacs merging mode, but I far prefer ediff.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜