What’s the difference between git diff –full-index and git diff –binary?

To understand the difference between git diff --full-index and git diff --binary, we first need to grasp the purpose of the git diff command. This command is a tool used to identify changes between commits, working trees, and files in a Git repository.

The options --full-index and --binary both modify the output of git diff, but they serve different purposes and are used in different scenarios. Let’s break down each option:

--full-index: This option makes the diff output display whole (unabbreviated) object names (SHA1 hashes) in diff raw format. Normally, Git abbreviates these hashes to the first few characters for easier readability. However, using --full-index will show the complete hash, which can be useful when you want to ensure absolute precision, such as when you’re generating machine-readable output.Here is an example of how a diff raw format line looks without --full-index:

:100644 100644 e69de29... 63a4a3f... M file.txt

And here’s the same line with --full-index:

:100644 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 63a4a3f4d98097779d4df3bdfd878ea72bed8f80 M file.txt

--binary: Git’s default diff output does not handle binary files – instead, it simply outputs a message indicating that the binary files are different. The --binary option changes this by generating a diff that can be applied with git apply, even for binary files. This can be useful when you’re working with binary files and want to create patches that include changes to those files.The output will include a binary diff in a format that can be used for patching, but it won’t be human-readable. In many cases, --binary diffs will be much larger than the equivalent text diffs.

To summarize:

  • --full-index is about displaying complete object names in diff raw format, providing absolute precision.
  • --binary is about including binary changes in the diff output, allowing binary changes to be captured in patches.

They serve different purposes and can even be used together if you need to generate a diff with complete object names that also includes binary changes.