1

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.

  • 5
    if you would like to be able to see which files were modified _before_ wrapping up the merge commit, you could run `git merge --no-commit`. When you are finished, run `git merge --continue` – eftshift0 Oct 23 '20 at 16:58
  • i'm using logic in a software using rugged gem. https://github.com/libgit2/rugged – Praveen Raghav Oct 23 '20 at 18:06
  • 2
    What you describe isn't what conflict detection is for, any solution based on conflict detection is likely to be fragile. A different solution might be better. Could you give some more detail about why these should be in conflict? Can this be solved with testing? – Schwern Oct 23 '20 at 18:19
  • 3
    *But i need git to return the operation as modified* I have no idea what that sentence means. Using a merge driver could let you stop the merge, but if you're doing the merge in software, use `git merge --no-commit` as eftshift0 suggested. – torek Oct 23 '20 at 20:34
  • @PraveenRaghav Is it always the same file? If so, you can use `.gitattributes` to mark it as binary – knittl Mar 30 '21 at 16:49

1 Answers1

0

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
knittl
  • 246,190
  • 53
  • 318
  • 364