Git: Add merge rule to config for specific file

流过昼夜 提交于 2019-12-06 07:29:34
VonC

All possible ways to simulate a merge -s theirs are listed in "git command for making one branch like another".

But for one file, all you need is a merge driver, declared in a .gitattributes file, with a keepTheir script like:

mv -f $3 $2
exit 0

See "git merge -s theirs” needed — but I know it doesn't exist" for a concrete example of a custom merge driver (including my own version).

2018 solution: Merge Drivers

In git config you can add custom merge drivers:

[merge "my-custom-driver"]
    name = A custom merge driver used to resolve conflicts in certain files
    driver = my-merge-tool.sh %O %A %B

but you can also just return 'true' for the driver which will always keep local changes:

[merge "keep-local-changes"]
    name = A custom merge driver which always keeps the local changes
    driver = true

Then in .gitattributes you can define which file types use which custom merge drivers:

/folder/**/*.fileExtension merge=keep-local-changes
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!