git should give me operation as conflict when same file modified in different branches

212 views Asked by At

Lets consider

file.txt

aaa
bbb
ccc

In branch A, I'm changing file content

file.txt

aaa-update
bbb
ccc

In branch B, I'm changing file content

file.txt

aaa
bbb
ccc-update

When I merge branch B into branch A I get below content.

file.txt

aaa-update
bbb
ccc-update

But i need git to return the operation as modified.

Similar question: avoid auto merging of git conflicts and warn if same files getting modified in different branches

I'm not sure if any merge strategy or merge driver ca help here.

Update: I need to use this logic in a software.

1

There are 1 answers

0
knittl On

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).

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.

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