Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 952
bartek Avatar asked Nov 27 '12 22:11

bartek


People also ask

How do I force git overwrite?

Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.

How do I accept all changes in merge conflict?

right click file with conflicts without left-click / opening file in editor pane. click "Accept all Incoming" / "Accept all Current" no changes are accepted, file in list remains unchanged.

Will git merge overwrite my changes?

Usually git does not overwrite anything during merge.


2 Answers

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".

like image 108
Renato Zannon Avatar answered Oct 01 '22 15:10

Renato Zannon


I use this,

git fetch --prune git reset --hard origin/master 
like image 33
wolfgang Avatar answered Oct 01 '22 14:10

wolfgang