2

When doing a merge with upstream, git defaults to putting conflict information right into the files. E.g.

Here are lines that are either unchanged from the common
ancestor, or cleanly resolved because only one side changed.
<<<<<<< yours:sample.txt
Conflict resolution is hard;
let´s go shopping.
=======
Git makes conflict resolution easy.
>>>>>>> theirs:sample.txt
And here is another line that is cleanly resolved or unmodified.

Is there a way to take their or my changes for the whole file without editing it all by hand?

EDIT: I know there are options to git merge and git pullwhich make the whole merge take one side, but once you started the merge in conflict mode, this is no longer possible. Aside from that I don't want to take ALL changes from one side, but decide manually per file.

Hubert Grzeskowiak
  • 15,137
  • 5
  • 57
  • 74
  • https://git-scm.com/docs/git-merge#_merge_strategies – axiac Feb 09 '17 at 09:29
  • Hi @axiac and thanks for your comment. I have updated my question as response to that. – Hubert Grzeskowiak Feb 09 '17 at 09:57
  • I don't understand what you need. A conflict, by its very nature, is a situation when the changes operated on two branches of the code cannot be combined automatically. You can tell Git to completely ignore the changes from the other side (no matter if they conflict or not) and use your version using `-s ours`. You can even tell it to merge the changes and solve the conflicts by ignoring one of the sides (`-s recursive -X ours` or `-X theirs`). Any other way to solve the conflicts requires human intervention. If they don't, they are not conflicts. That's the whole point. – axiac Feb 09 '17 at 10:05
  • 1
    @axiac the OP wants to manually resolve the conflict; to look at each file and choose, in some cases, to take *theirs* or *ours* – Mario Trucco Feb 09 '17 at 10:07

1 Answers1

2

Assuming you do not only want to use the command-line

Among others, IntelliJ IDEA or KDiff3 proposes such features. You can accept change for a whole file or do it line-by-line.

If you do want to do it with vanilla git

First list all the differences with the remote branch and then checkout each file separately like this:

git checkout --ours fileIwantToKeep.txt 
git checkout --theirs fileIwantToOverwrite.txt
Community
  • 1
  • 1
Olivier Tonglet
  • 3,312
  • 24
  • 40