In git merge conflicts, how do I keep the version that is being merged in?

后端 未结 2 376
我寻月下人不归
我寻月下人不归 2021-01-04 08:25

I have two local git branches on my machine - a branch called \"v2\" and a branch called \"master\". I\'m merging v2 into master while master is checked out and the head br

2条回答
  •  梦谈多话
    2021-01-04 09:25

    If you're looking to keep v2 hands down (I want master to look exactly like v2), I think the easiest way is to:

    • Checkout the branch you want to merge
    • Merge master into the branch with the ours strategy
    • Checkout master
    • Merge the branch

    It would look like this:

    git checkout v2
    git merge -s ours master
    git checkout master
    git merge v2
    

    If you just want this type of resolution to happen only on conflicts, then you can do:

    git checkout master
    git merge -s recursive -Xtheirs v2
    

    You can read up on merge strategies in the git documentation here.

    UPDATE: unfortunately, I don't think Git Tower exposes a way to do this yet. :-(

提交回复
热议问题