Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://git.kernel.org/?p=git/git.git;a=blob;f=diff.c;h=8f4815bfd7d798f2a99131cd2e79155e933c7876;hb=HEAD#l2002"><code>builtin_diff()</code></a><sup>1</sup> calls <a href="http://git.kernel.org/?p=git/git.git;a=blob;f=diff.c;h=8f4815bfd7d798f2a99131cd2e79155e933c7876;hb=HEAD#l1942"><code>diff_filespec_is_binary()</code></a> which calls <a href="http://git.kernel.org/?p=git/git.git;a=blob;f=xdiff-interface.c;h=0e2c169227ad29b5bf546c6c1b97e1a1d8ed7409;hb=HEAD#l241"><code>buffer_is_binary()</code></a> which checks for any occurrence of a zero byte (NUL “character”) in the first 8000 bytes (or the entire length if shorter).</p> <p>I do not see that this “is it binary?” test is explicitly exposed in any command though.</p> <p><code>git merge-file</code> directly uses <code>buffer_is_binary()</code>, so you may be able to make use of it:</p> <pre><code>git merge-file /dev/null /dev/null file-to-test </code></pre> <p>It seems to produce the error message like <code>error: Cannot merge binary files: file-to-test</code> and yields an exit status of 255 when given a binary file. I am not sure I would want to rely on this behavior though.</p> <p>Maybe <code>git diff --numstat</code> would be more reliable:</p> <pre><code>isBinary() { p=$(printf '%s\t-\t' -) t=$(git diff --no-index --numstat /dev/null "$1") case "$t" in "$p"*) return 0 ;; esac return 1 } isBinary file-to-test &amp;&amp; echo binary || echo not binary </code></pre> <p>For binary files, the <code>--numstat</code> output should start with <code>-</code> TAB <code>-</code> TAB, so we just test for that.</p> <hr> <p><sup>1</sup> <code>builtin_diff()</code> has strings like <code>Binary files %s and %s differ</code> that should be familiar.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload