bartek
bartek

Reputation: 3021

Force Git to always choose the newer version during a merge?

Let's assume I merge git and there is a merge conflict.

My question is: how can I force git to always choose the newer version of code in conflict so I won't need to resolve the conflict by hand?

Upvotes: 116

Views: 102078

Answers (3)

SmoothKen
SmoothKen

Reputation: 141

Take a look at my answer in Git timestamp based automated sync

Essentially we have to do manual timestamp comparison. I do not think git merge has any built-in utility for this.

Upvotes: 1

wolfgang
wolfgang

Reputation: 7789

I use this,

git fetch --prune
git reset --hard origin/master

Upvotes: 23

Renato Zannon
Renato Zannon

Reputation: 29951

It is not exactly the "newer" version, but you can tell git to always prefer the version on the current branch using git merge branch -X ours, or to prefer the version of the branch being merged, using git merge branch -X theirs.

From man git-merge:

ours:

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.

theirs:

This is the opposite of "ours".

Upvotes: 213

Related Questions