merge strategy in .gitattributes not working

妖精的绣舞 提交于 2019-12-19 11:03:24

问题


I want git to never have a conflict on this file:
test/file.txt
when merging. I tried the following in .gitattributes test/file.txt merge=theirs

but I need to define the theirs merge strategy. I saw online that I can define the ours strategy by executing this:
git config --global merge.theirs.driver true
which sets the driver to true (bash true) which will keep the local file instead of the new one.
I want to do the opposite. How can I define the theirs driver to get the new copy and discard the local one when merging (after a git pull)?


回答1:


How can I define the theirs driver to get the new copy and discard the local one when merging (after a git pull)?

As I mentioned in "How do I tell git to always select my local version for conflicted merges on a specific file?", you would need to call a script like:

git config merge.keepTheir.name "always keep their during merge"
git config merge.keepTheir.driver "keepTheir.sh %O %A %B"

With keepTheir.sh (put anywhere in your PATH)

cp -f $3 $2
exit 0

Or, as jthill suggests below in the comments, directly:

git config merge.keepTheir.driver "cp -f %B %A"


来源:https://stackoverflow.com/questions/27920526/merge-strategy-in-gitattributes-not-working

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