2

I am looking for a git command that will do merging of other branch (like develop) into mine with:

  1. automatic resolving conflicts,
  2. when there are conflicts that are not possible to resolve with automatic merge, then take my version of changes.

I tried using commands like git merge -s ours but it then takes my changes in all conflicts. And this is not what I want. If for example version of package that I didn't change has been updated on the branch that I am merging into mine, I want obviously this package to be updated.

Any help here much appreciated!

10
  • 1
    You can't generally do exactly what you want, I think. There can always be conflicts which Git can't figure out how to handle, and, in this case, you would absolutely want to resolve them manually. Commented Oct 31, 2018 at 12:48
  • Yes and in this case - that Git can't resolve those changes I want to take my version of files. Commented Oct 31, 2018 at 12:49
  • Possible duplicate of How to prefer files from one branch during a merge? Commented Oct 31, 2018 at 12:50
  • 2
    Did you try git merge -s recursive -X ours? Commented Oct 31, 2018 at 12:53
  • 2
    No, -s ours does not merely take your changes in all conflicts. -s ours doesn't actually do anything with conflicts, it throws all the changes that the other side made away and just takes your entire tree. It looks like a merge has been done, but the other side's code is not merged at all, it's discarded. This is an incredibly dangerous command and - as you note - it's not what you want. (I wanted to clarify what it does do for future readers who might be inclined to try to use it.) Commented Oct 31, 2018 at 15:16

1 Answer 1

0

Can you tell me what exactly git merge -s recursive -X ours do then?

First, in case of 3-way merge, the recursive strategy is the default one.
-X ours will be an option passed to that specific strategy.

As illustrated here, the ours option will be applied in case of conflict only:

This option forces conflicting hunks to be auto-resolved cleanly by favoring our version. Changes from the other tree that do not conflict with our side are reflected to the merge result. For a binary file, the entire contents are taken from our side.

This should not be confused with the ours merge strategy, which does not even look at what the other tree contains at all. It discards everything the other tree did, declaring our history contains all that happened in it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.