1

I am getting familiar with how the merge command works and came upon the following unexpected case.

I noticed that trying to merge two commits, both of which edited a UTF-16 encoded file, Git failed to point out the changes made on both branches (the ones that are usually denoted with >>>>>> and <<<<<<). What it did is just leave the content of the version of the file that was under HEAD.

I tried to see the difference between them using the Git diff command, but Git reported that it considers them as binary files instead of text files. I assume this could be the reason the merge didn't work as expected.

Note - Changing the default encoding of the edited file to UTF-8 solves both the problem with the diff and with the merge command.

Is there a way we can merge commits that have edited the same non-UTF-8 encoded file and ensure Git would indicate if, and in case - where exactly, conflicts occur?

Kaloyan
  • 41
  • 1
  • 6
  • 2
    Related https://stackoverflow.com/questions/777949/can-i-make-git-recognize-a-utf-16-file-as-text and https://stackoverflow.com/questions/18112050/git-cant-diff-or-merge-cs-file-in-utf-16-encoding – evolutionxbox Aug 10 '22 at 11:58
  • Thanks! The first thread indeed gives a solution to the `diff` problem but the `merge` one remains unresolved. To be more precise, I have altered the question. – Kaloyan Aug 10 '22 at 12:28
  • There are some references to "merge" in the answers in the duplicate, e.g., https://stackoverflow.com/a/1300928/3216427 . Maybe try setting `merge.tool` to vimdiff or gvimdiff or BeyondCompare? (Full disclosure, I've never tried this, but I would be interested to hear if it works.) – joanis Aug 10 '22 at 13:35
  • 1
    Actually, I have found the solution to my question after consulting with the gitattributes documentation mentioned in the following answer - https://stackoverflow.com/a/54683489/16812115. I have also posted a short summary of what I found here - https://stackoverflow.com/a/73307127/16812115. – Kaloyan Aug 10 '22 at 13:53
  • @Kaloyan Thanks for adding that write up in the duplicate, I think it's helpful. And I guess I'm alone with that opinion, because dang, it just got deleted... :( – joanis Aug 10 '22 at 20:33
  • In any case, if you haven't already done so, you can upvote the answer that helped you there, I assume the one you linked to. – joanis Aug 10 '22 at 20:34
  • I added a comment and upvote to your answer in the duplicate. – torek Aug 11 '22 at 01:26

0 Answers0