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?
Just like git push --force allows overwriting remote branches, git fetch --force (or git pull --force ) allows overwriting local branches.
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.
Usually git does not overwrite anything during merge.
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".
I use this,
git fetch --prune git reset --hard origin/master
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With