{"thread":{"id":"59534","subject":"\"git diff\" does not show a diff for newly added, binary files","startedAt":"2023-04-04T10:05:04Z","lastAt":"2023-04-04T15:42:59Z","messageCount":10,"participants":["Thorsten Otto","Kristoffer Haugsbakk","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"474767","messageId":"3473764.PTxrJRyG3s@earendil","threadId":"59534","inReplyTo":null,"subject":"\"git diff\" does not show a diff for newly added, binary files","fromName":"Thorsten Otto","fromEmail":"admin@tho-otto.de","sentAt":"2023-04-04T09:58:38Z","receivedAt":"2023-04-04T10:05:04Z","isPatch":false,"sender":{"key":"admin@tho-otto.de","avatar":null},"body":"\"git diff\" does not show a diff for newly added, binary files\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\n$ git init .\n$ touch a\n$ git add a\n$ git commit -m \"first commit\"\n$ dd if=/dev/zero of=b count=1\n$ git add b\n$ echo hello > c\n$ git add c\n$ git diff --cached\n\nWhat did you expect to happen? (Expected behavior)\n\nI expected a binary diff for the new file, just like it is done\nwhen comparing two different, already committed revisions.\n\nWhat happened instead? (Actual behavior)\n\nThe \"git diff\" command only showed a diff for the text file c, \nbut not for the binary file b:\n\ndiff --git a/b b/b\nnew file mode 100644\nindex 0000000..a64a5a9\nBinary files /dev/null and b/b differ\ndiff --git a/c b/c\nnew file mode 100644\nindex 0000000..ce01362\n--- /dev/null\n+++ b/c\n@@ -0,0 +1 @@\n+hello\n\n[System Info]\ngit version:\ngit version 2.39.0\ncpu: x86_64\nno commit associated with this build\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nuname: Linux 6.1.3-1-default #1 SMP PREEMPT_DYNAMIC Wed Jan  4 11:03:53 UTC \n2023 (a5315fb) x86_64\ncompiler info: gnuc: 12.2\nlibc info: glibc: 2.36\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\n\n\n\n"},{"id":"474768","messageId":"8135fc7b-1953-4702-a9c4-b0f847e69887@app.fastmail.com","threadId":"59534","inReplyTo":"3473764.PTxrJRyG3s@earendil","subject":"Re: \"git diff\" does not show a diff for newly added, binary files","fromName":"Kristoffer Haugsbakk","fromEmail":"code@khaugsbakk.name","sentAt":"2023-04-04T10:17:43Z","receivedAt":"2023-04-04T10:19:03Z","isPatch":false,"sender":{"key":"code@khaugsbakk.name","avatar":"https://avatars.githubusercontent.com/u/2229597?v=4"},"body":"On Tue, Apr 4, 2023, at 11:58, Thorsten Otto wrote:\n> \"git diff\" does not show a diff for newly added, binary files\n> […]\n> I expected a binary diff for the new file, just like it is done\n> when comparing two different, already committed revisions.\n\nDo you use `.gitattributes` to get these binary diffs? What does it look like?\n\n-- \nKristoffer Haugsbakk\n"},{"id":"474769","messageId":"2349908.kWcu0K8Tai@earendil","threadId":"59534","inReplyTo":"8135fc7b-1953-4702-a9c4-b0f847e69887@app.fastmail.com","subject":"Re: \"git diff\" does not show a diff for newly added, binary files","fromName":"Thorsten Otto","fromEmail":"admin@tho-otto.de","sentAt":"2023-04-04T10:39:09Z","receivedAt":"2023-04-04T10:44:57Z","isPatch":false,"sender":{"key":"admin@tho-otto.de","avatar":null},"body":"On Dienstag, 4. April 2023 12:17:43 CEST Kristoffer Haugsbakk wrote:\n\n> Do you use `.gitattributes` to get these binary diffs? What does it look\n> like?\n\nNo, the repo was just created for demonstrating purposes. But when i commit \nthat last change, then do a \"git --format-patch -1\", i get something like\n\ndiff --git a/b b/b\nnew file mode 100644\nindex \n0000000000000000000000000000000000000000..a64a5a93fb4aef4d5f63d79cb2582731b9ac5063\nGIT binary patch\nliteral 512\nNcmZQz7zHCa1ONg600961\n\nliteral 0\nHcmV?d00001\n\n\nI would expect \"git diff\" to output the same information. I don't see a reason \nwhy it outputs the diff for a new text file, but not for a binary file?\n\n\n\n\n\n"},{"id":"474770","messageId":"4e5ac983-a45d-4459-b398-4d092ca2f1c8@app.fastmail.com","threadId":"59534","inReplyTo":"2349908.kWcu0K8Tai@earendil","subject":"Re: \"git diff\" does not show a diff for newly added, binary files","fromName":"Kristoffer Haugsbakk","fromEmail":"code@khaugsbakk.name","sentAt":"2023-04-04T10:45:35Z","receivedAt":"2023-04-04T10:46:14Z","isPatch":false,"sender":{"key":"code@khaugsbakk.name","avatar":"https://avatars.githubusercontent.com/u/2229597?v=4"},"body":"On Tue, Apr 4, 2023, at 12:39, Thorsten Otto wrote:\n> I would expect \"git diff\" to output the same information. I don't see a reason \n> why it outputs the diff for a new text file, but not for a binary file?\n\nHas it done that before? As in, has git(1) behaved like the way you expect \nit to behave on this point before? Because `git diff` has never diffed\nbinary files for me unless I instructed it to do it via some `.gitattributes`\nconfiguration.\n\n-- \nKristoffer Haugsbakk\n"},{"id":"474772","messageId":"1997583.yJf2vTnlun@earendil","threadId":"59534","inReplyTo":"4e5ac983-a45d-4459-b398-4d092ca2f1c8@app.fastmail.com","subject":"Re: \"git diff\" does not show a diff for newly added, binary files","fromName":"Thorsten Otto","fromEmail":"admin@tho-otto.de","sentAt":"2023-04-04T11:23:11Z","receivedAt":"2023-04-04T11:23:29Z","isPatch":false,"sender":{"key":"admin@tho-otto.de","avatar":null},"body":"On Dienstag, 4. April 2023 12:45:35 CEST Kristoffer Haugsbakk wrote:\n> Has it done that before?\n\nNot that a know of.\n\n>unless I instructed it to do it via some `.gitattributes`\n>configuration.\n\nHow can that be done? I mean, git detects that file to be binary. I certainly \ndon't want to treat it as text, and then dump binary data to the terminal when \nthey differ ;)\n\n\n\n\n"},{"id":"474773","messageId":"fa47135f-48f7-4cf9-b239-ebdd5b9872d0@app.fastmail.com","threadId":"59534","inReplyTo":"1997583.yJf2vTnlun@earendil","subject":"Re: \"git diff\" does not show a diff for newly added, binary files","fromName":"Kristoffer Haugsbakk","fromEmail":"code@khaugsbakk.name","sentAt":"2023-04-04T11:29:25Z","receivedAt":"2023-04-04T11:30:01Z","isPatch":false,"sender":{"key":"code@khaugsbakk.name","avatar":"https://avatars.githubusercontent.com/u/2229597?v=4"},"body":"On Tue, Apr 4, 2023, at 13:23, Thorsten Otto wrote:\n> How can that be done? I mean, git detects that file to be binary. I certainly \n> don't want to treat it as text, and then dump binary data to the terminal when \n> they differ ;)\n\nI used something like this when I last needed to diff binary files: https://superuser.com/a/706286/259670\n\n-- \nKristoffer Haugsbakk\n"},{"id":"474781","messageId":"20230404153615.GA160693@coredump.intra.peff.net","threadId":"59534","inReplyTo":"2349908.kWcu0K8Tai@earendil","subject":"Re: \"git diff\" does not show a diff for newly added, binary files","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-04-04T15:36:15Z","receivedAt":"2023-04-04T15:37:13Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Apr 04, 2023 at 12:39:09PM +0200, Thorsten Otto wrote:\n\n> On Dienstag, 4. April 2023 12:17:43 CEST Kristoffer Haugsbakk wrote:\n> \n> > Do you use `.gitattributes` to get these binary diffs? What does it look\n> > like?\n> \n> No, the repo was just created for demonstrating purposes. But when i commit \n> that last change, then do a \"git --format-patch -1\", i get something like\n> \n> diff --git a/b b/b\n> new file mode 100644\n> index \n> 0000000000000000000000000000000000000000..a64a5a93fb4aef4d5f63d79cb2582731b9ac5063\n> GIT binary patch\n> literal 512\n> NcmZQz7zHCa1ONg600961\n> \n> literal 0\n> HcmV?d00001\n> \n> \n> I would expect \"git diff\" to output the same information. I don't see a reason \n> why it outputs the diff for a new text file, but not for a binary file?\n\nThe behavior you're seeing is expected.\n\nThe default for \"git diff\" is not to show binary patches, because they\nare often gigantic, and are meaningless to human readers. You can use\n\"--binary\" if you want to see them.\n\nThe default for \"git format-patch\" is different, because there the point\nis to send the patch to somebody to be applied with \"git am\", so it's\nimportant that all information is included.\n\n-Peff\n"},{"id":"474782","messageId":"xmqqo7o33bgt.fsf@gitster.g","threadId":"59534","inReplyTo":"3473764.PTxrJRyG3s@earendil","subject":"Re: \"git diff\" does not show a diff for newly added, binary files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-04-04T15:37:22Z","receivedAt":"2023-04-04T15:38:15Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thorsten Otto <admin@tho-otto.de> writes:\n\n> \"git diff\" does not show a diff for newly added, binary files\n\nThe command is working as designed, either for newly added ones,\nmodified ones, or deleted ones.  In your sample output, we can see\n\"Binary files differ\", which is the default \"diff\" for binary\ncontents.  It is in line with the way \"diff\" by other people work.\n\n> What happened instead? (Actual behavior)\n>\n> The \"git diff\" command only showed a diff for the text file c, \n> but not for the binary file b:\n>\n> diff --git a/b b/b\n> new file mode 100644\n> index 0000000..a64a5a9\n> Binary files /dev/null and b/b differ\n> diff --git a/c b/c\n> new file mode 100644\n> index 0000000..ce01362\n> --- /dev/null\n> +++ b/c\n> @@ -0,0 +1 @@\n> +hello\n\nAs the primary purpose of \"git format-patch\" is to convey the\ncontent change between pair of states (i.e. change to bring the\nstate at a particular commit to another state at a commit that is\nits child), it implicitly enables the \"binary patch\" option, but for\n\"git diff\" which is meant to be an interactive browser of changes\nfor human consumption, the \"binary patch\" option is off by default.\n\nYou can run \"git diff --binary\".\n"},{"id":"474783","messageId":"20230404153918.GB160693@coredump.intra.peff.net","threadId":"59534","inReplyTo":"3473764.PTxrJRyG3s@earendil","subject":"Re: \"git diff\" does not show a diff for newly added, binary files","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-04-04T15:39:18Z","receivedAt":"2023-04-04T15:39:54Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Apr 04, 2023 at 11:58:38AM +0200, Thorsten Otto wrote:\n\n> \"git diff\" does not show a diff for newly added, binary files\n> \n> What did you do before the bug happened? (Steps to reproduce your issue)\n> \n> $ git init .\n> $ touch a\n> $ git add a\n> $ git commit -m \"first commit\"\n> $ dd if=/dev/zero of=b count=1\n> $ git add b\n> $ echo hello > c\n> $ git add c\n> $ git diff --cached\n> \n> What did you expect to happen? (Expected behavior)\n> \n> I expected a binary diff for the new file, just like it is done\n> when comparing two different, already committed revisions.\n\nI responded elsewhere in the thread mentioning \"git diff --binary\", but\nnote this part of the report is a little misleading. The difference is\nnot showing newly added files versus committed revisions. The difference\nis between \"git diff\" and \"git format-patch\". If you commit the result\nabove and then run:\n\n  git diff HEAD^ HEAD\n\nit will likewise not show the binary patch (unless you specify\n--binary). Likewise for \"git show\", etc. I think that format-patch is\nthe only command with binary diffs turned on by default.\n\n-Peff\n"},{"id":"474784","messageId":"xmqqjzyr3b8e.fsf@gitster.g","threadId":"59534","inReplyTo":"8135fc7b-1953-4702-a9c4-b0f847e69887@app.fastmail.com","subject":"Re: \"git diff\" does not show a diff for newly added, binary files","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-04-04T15:42:25Z","receivedAt":"2023-04-04T15:42:59Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Kristoffer Haugsbakk\" <code@khaugsbakk.name> writes:\n\n> On Tue, Apr 4, 2023, at 11:58, Thorsten Otto wrote:\n>> \"git diff\" does not show a diff for newly added, binary files\n>> […]\n>> I expected a binary diff for the new file, just like it is done\n>> when comparing two different, already committed revisions.\n>\n> Do you use `.gitattributes` to get these binary diffs? What does it look like?\n\nThe attribute \"binary\" can be used like this\n\n    *.mybin\tbinary\n\nto declare that all files with .mybin suffix are to be treated\nbinary files.  \"git diff\", \"git format-patch\", etc. will treat\nsuch a file as \"binary\".\n\nWhat they actually do to \"binary files\" is a different story.  The\ninternal diff machinery by default shows \"Binary files A and B differ\"\njust like everybody else's \"diff\" program does, but has an option to\nshow \"binary patch\" we invented.  \"git diff --binary\" enables the option,\nand for some commands, the option is enabled by default.\n"}]}