4

I have a file call a.uni, and I have to merge the solution. But git treat a.uni as binary file. When I merge the solution, it always shows:

warning: Cannot merge binary files: a.uni (HEAD vs. 549af46... test) error: could not apply 549af46... test hint: after resolving the conflicts, mark the corrected paths hint: with 'git add ' or 'git rm ' hint: and commit the result with 'git commit' Can somebody else help me!!! thanks a lot.

kane
  • 287
  • 3
  • 8

2 Answers2

4

Since your .uni file is actually a text file, I suppose it must have some NUL character in it (see "How to determine if Git handles a file as binary or as text?").

It depends on how you want to manage the merge.

As mentioned in "Tell git not to merge binary files but to choose", you can specify a merge manager in a .gitattributes file which will merge according to your policy.

At least, as in "why does git treat some cpp files as binary?", you can try and specify (still ion the .gitattributes file):

*.uni -text crlf diff

For Unicode files, looking at "Can I make git recognize a UTF-16 file as text?", you can:

  • either define a custom diff or merge tool supporting that format: git config --global diff.tool vimdiff ; git difftool commit1 commit2
  • or define an attribute like: *.uni diff merge -crlf

You should also make sure:

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Now, I know why git treat my file as binary. Because it is a unicode file. But I still don't know how to solve that~~~ – kane Nov 21 '12 at 07:13
  • @user1584490 did you try the `*.uni -text crlf diff` gitattributes directive? – VonC Nov 21 '12 at 07:22
  • @user1584490 I have edited my answer to address the unicode nature of your `*.uni` files. – VonC Nov 22 '12 at 06:40
  • Is '-' sign a typo? '-text' means binary, but we want to set file as text. See https://git-scm.com/docs/gitattributes – Michael Freidgeim May 12 '16 at 00:29
  • @MichaelFreidgeim at the time (2011), the justification from the OP http://stackoverflow.com/q/4735663/6309 was "The `-text` part was needed to keep git from converting lineends, even though `core.autocrlf` is set to `false`". Nowadays (2016, git 2.8+), I would remove the `-text` and try it again, with `core.autocrlf` still set to `false`. – VonC May 12 '16 at 06:19
0

Did the encoding type of the .uni file change (e.g. UTF-8 to ANSI)? Git doesn't seem to be able to compare/merge files of different encoding types. See the answer I gave on this post.

Community
  • 1
  • 1
deadlydog
  • 22,611
  • 14
  • 112
  • 118