git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: "git diff" does not show a diff for newly added, binary files

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 4, 2023, 15:37 UTC
Message-ID
<xmqqo7o33bgt.fsf@gitster.g>
In-Reply-To
<3473764.PTxrJRyG3s@earendil>
Thorsten Otto <admin@tho-otto.de> writes:
> "git diff" does not show a diff for newly added, binary files

The command is working as designed, either for newly added ones, modified ones, or deleted ones. In your sample output, we can see "Binary files differ", which is the default "diff" for binary contents. It is in line with the way "diff" by other people work.

Show 16 quoted lines
> What happened instead? (Actual behavior)
>
> The "git diff" command only showed a diff for the text file c, 
> but not for the binary file b:
>
> diff --git a/b b/b
> new file mode 100644
> index 0000000..a64a5a9
> Binary files /dev/null and b/b differ
> diff --git a/c b/c
> new file mode 100644
> index 0000000..ce01362
> --- /dev/null
> +++ b/c
> @@ -0,0 +1 @@
> +hello

As the primary purpose of "git format-patch" is to convey the content change between pair of states (i.e. change to bring the state at a particular commit to another state at a commit that is its child), it implicitly enables the "binary patch" option, but for "git diff" which is meant to be an interactive browser of changes for human consumption, the "binary patch" option is off by default.

You can run "git diff --binary".
Previous: Junio C HamanoNext: Jeff King
Message 9 of 10 in “"git diff" does not show a diff for newly added, binary files”
  1. Thorsten OttoApr 4, 2023
  2. Kristoffer HaugsbakkApr 4, 2023
  3. Thorsten OttoApr 4, 2023
  4. Kristoffer HaugsbakkApr 4, 2023
  5. Thorsten OttoApr 4, 2023
  6. Kristoffer HaugsbakkApr 4, 2023
  7. Jeff KingApr 4, 2023
  8. Junio C HamanoApr 4, 2023
  9. Junio C HamanoApr 4, 2023
  10. Jeff KingApr 4, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.