{"thread":{"id":"40902","subject":"Re: [git-for-windows] How is detected binary files?","startedAt":"2015-11-27T14:14:58Z","lastAt":"2015-12-02T00:49:21Z","messageCount":2,"participants":["Johannes Schindelin","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"273798","messageId":"alpine.DEB.1.00.1511271510520.1686@s15462909.onlinehome-server.info","threadId":"40902","inReplyTo":"487b881f-9e3e-4d22-ba1e-af3beeaccd6e@googlegroups.com","subject":"Re: [git-for-windows] How is detected binary files?","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2015-11-27T14:14:58Z","receivedAt":"2015-11-27T14:14:58Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Andrzej,\n\nOn Wed, 25 Nov 2015, Andrzej Borucki wrote:\n\n> How git detects that file is binary? This must be safe because it not \n> allowed to change line breaks in binary files. \n> Binary files can contain byte 0 (zero), but:\n> - 16 bit UTF also can contain zero\n> - short binary files can not contain zero\n\nIt would probably be better to direct this question to the general Git\nmailing list (you reached the Git for Windows one, and this issue is not\nspecific to Windows).\n\nTo answer your question, a NUL byte within the first 8000 bytes is indeed\nconsidered as an indicator for binary files.\n\nIf you use UTF-16, you will need to mark your files as such explicitly\n(Git does not handle UTF-16 internally).\n\nAs to short binary files, you will also have to mark those explicitly.\n\nCiao,\nJohannes\n"},{"id":"273890","messageId":"20151202004921.GC28197@sigill.intra.peff.net","threadId":"40902","inReplyTo":"alpine.DEB.1.00.1511271510520.1686@s15462909.onlinehome-server.info","subject":"Re: [git-for-windows] How is detected binary files?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-12-02T00:49:21Z","receivedAt":"2015-12-02T00:49:21Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Nov 27, 2015 at 03:14:58PM +0100, Johannes Schindelin wrote:\n\n> On Wed, 25 Nov 2015, Andrzej Borucki wrote:\n> \n> > How git detects that file is binary? This must be safe because it not \n> > allowed to change line breaks in binary files. \n> > Binary files can contain byte 0 (zero), but:\n> > - 16 bit UTF also can contain zero\n> > - short binary files can not contain zero\n> \n> It would probably be better to direct this question to the general Git\n> mailing list (you reached the Git for Windows one, and this issue is not\n> specific to Windows).\n> \n> To answer your question, a NUL byte within the first 8000 bytes is indeed\n> considered as an indicator for binary files.\n> \n> If you use UTF-16, you will need to mark your files as such explicitly\n> (Git does not handle UTF-16 internally).\n\nI'm not sure if it is a good idea to treat UTF-16 as text. The rest of\nthe diff (headers, etc) will all be in ASCII, so one or the other is\ngoing to be mojibake.\n\nYou can get readable diffs by textconv-ing them to an ASCII-superset\nencoding like UTF-8. Something like:\n\n    echo 'myfile diff=utf16' >.gitattributes\n    git config diff.utf16.textconv 'iconv -f utf16 -t utf8'\n\nbut of course the resulting patches cannot be applied, and you may miss\nany changes that do not make it through the encoding (e.g., using\ndifferent bytes to represent the same code point).\n\n-Peff\n"}]}