How to automatically resolve a Git conflict by taking the version in the current branch?

前端 未结 2 586
执念已碎
执念已碎 2021-02-01 04:05

Let\'s suppose that I get a merge conflict on foo/bar.txt when running this:

$ git checkout A
$ git merge B

I\'d like to automatic

2条回答
  •  悲&欢浪女
    2021-02-01 04:51

    If you want to do it as a one-off, the single-line command is:

    $ git checkout --ours foo/bar.txt  # <-- resets it only if the merge found conflicts in this file
    $ git checkout HEAD -- foo/bar.txt # <-- resets it to that specific version no matter what
    

    To configure git's merge to permanently ignore all upstream changes to a locally-changed file:

    $ git config merge.pin.driver true
    $ echo foo/bar.txt merge=pin >> .git/info/attributes
    

    (true above is just the unix true command, its success says it made the local version look right, in this case by doing nothing to it. You can of course get more sophisticated with your merge commands.)

    I think you don't want merge --strategy=ours or --strategy-option=ours, those apply to entire merges.

提交回复
热议问题