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!

Marta
  • 2,857
  • 13
  • 46
  • 67
  • 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. – Tim Biegeleisen Oct 31 '18 at 12:48
  • Yes and in this case - that Git can't resolve those changes I want to take my version of files. – Marta Oct 31 '18 at 12:49
  • Possible duplicate of [How to prefer files from one branch during a merge?](https://stackoverflow.com/questions/17704119/how-to-prefer-files-from-one-branch-during-a-merge) – Liam Oct 31 '18 at 12:50
  • For the second part of your question, yes, something like that can be done, but it's almost certainly be answered before somewhere on Stack Overflow. Poke around for 5-10 minutes and I bet you'll find something. – Tim Biegeleisen Oct 31 '18 at 12:50
  • Also [How do I tell git to always select my local version for conflicted merges on a specific file?](https://stackoverflow.com/questions/928646/how-do-i-tell-git-to-always-select-my-local-version-for-conflicted-merges-on-a-s) – Liam Oct 31 '18 at 12:52
  • I already poked for 2 hours and didn't find command that work well for my changes. My common scenario is that I have updated some nugget pacages, and other has been updated on develop. And I have got ton of merging conflicts. – Marta Oct 31 '18 at 12:53
  • 2
    Did you try `git merge -s recursive -X ours`? – L3viathan Oct 31 '18 at 12:53
  • I seem to of found two duplicates in a very short space of time. Is there a reason these options won't work for you? – Liam Oct 31 '18 at 12:54
  • 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.) – Edward Thomson Oct 31 '18 at 15:16
  • Thank you Edward Thomas for clarification. It is indeed helpful. Can you tell me what exactly *git merge -s recursive -X ours* do then? – Marta Nov 02 '18 at 07:08

1 Answers1

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.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250