我已从一个非常活跃的存储库中创建了自己的dev
分支。此存储库(Clappr)还包含一个已编译和缩小的文件,该文件使用源代码进行更新。
每当我想用dev
重新绑定我的master
分支时,这个文件是冲突的,因为它不能自动合并 - 当然,因为它是一个缩小的JS文件:
$ git checkout dev
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: dummy commit
Using index info to reconstruct a base tree...
M dist/clappr.js
M src/playbacks/hls/hls.js
Falling back to patching base and 3-way merge...
Auto-merging src/playbacks/hls/hls.js
Auto-merging dist/clappr.js
CONFLICT (content): Merge conflict in dist/clappr.js
我可以使用--ours
解决此冲突,但我必须对{尚未重新定位的master
上的每一次提交执行此操作。
我知道我可以完全跳过一个补丁,但是我可以以某种方式自动告诉Git忽略clappr.js
文件并且总是使用dev
分支中的任何内容吗?
答案 0 :(得分:3)
您可以定义自定义合并驱动程序(如“Git: How to rebase many branches (with the same base commit) at once?”中的具体示例)。
与keepMine
关联的合并驱动程序“dist/clappr.js
”,并在每个分支中的.gitattributes
文件中声明合并驱动程序。
请参阅“How do I tell git to always select my local version for conflicted merges on a specific file?”。
echo clappr.js merge=keepMine > dist/.gitattributes
git config merge.keepMine.name "always keep mine during merge"
git config merge.keepMine.driver "keepMine.sh %O %A %B"
将keepMine.sh
放在$PATH
中,而不是存储库中
# I want to keep MY version when there is a conflict
# Nothing to do: %A (the second parameter) already contains my version
# Just indicate the merge has been successfully "resolved" with the exit status
exit 0
(对于KeepTheir.sh
,请参阅“How to stop a merge (yet again…)”)