当在不同分支中修改相同文件时,git应该给我操作作为冲突 [英] git should give me operation as conflict when same file modified in different branches
问题描述
让我们考虑
file.txt
aaa
bbb
ccc
在分支A中,我正在更改文件内容
In branch A, I'm changing file content
file.txt
aaa-update
bbb
ccc
在分支B中,我正在更改文件内容
In branch B, I'm changing file content
file.txt
aaa
bbb
ccc-update
当我将分支B合并到分支A中时,我得到的内容不足.
When I merge branch B into branch A I get below content.
file.txt
aaa-update
bbb
ccc-update
但是我需要git返回修改后的操作.
But i need git to return the operation as modified.
类似的问题:避免自动合并git冲突并警告是否在不同分支中修改了相同文件
我不确定这里是否有任何合并策略或合并驱动程序可以帮助您.
I'm not sure if any merge strategy or merge driver ca help here.
更新:我需要在软件中使用此逻辑.
Update: I need to use this logic in a software.
推荐答案
我假设文件将始终是同一文件(或至少具有相同文件名模式(例如,匹配扩展名)的文件).
I'm assuming the file will always be the same file (or at least files with the same filename pattern, e.g. matching an extension).
在这种情况下,请创建 .gitattributes
文件将文件标记为二进制.二进制文件永远不会自动合并,合并时总是显示为冲突.
In that case, create a .gitattributes
file to mark the file as binary. Binary files will never be merged automatically and always show up as conflict when merging.
也可以仅禁用一个或多个文件的合并.您可以通过取消设置 merge
属性来做到这一点:
It is also possible to only disable merging for one or more files. You can do this by unsetting the merge
attribute:
# example content of .gitattributes:
filename -merge
*.ext binary
这篇关于当在不同分支中修改相同文件时,git应该给我操作作为冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!