git diff --raw is a command used in Git, a popular version control system. It provides a way to view changes between commits, commit and working tree, etc., in a ‘raw’ format.
git diff command is primarily used to show changes between two things. It could be between two commits, between the current working directory and the index, or other combinations.
--raw option changes the output format to a ‘raw’ style, which is a simple and readable format that git internally uses. This raw format provides information about what happened to the files between two snapshots in a very succinct way.
Each line of the raw output generally looks like this:
:100644 100755 a3d6e8d 0123456 M file.txt
This line can be read as follows:
100755: These are the old and new file modes, respectively, given in octal. The mode of a file refers to the file permissions, such as whether the file is readable, writable, or executable.
0123456: These are the old and new blob object hashes, respectively. A blob object hash represents a version of the file.
M: This is a status letter that tells what happened to the file. The most common status letters are:
Afor added files,
Mfor modified files,
Dfor deleted files.
file.txt: The name of the file that was changed.
You might use
git diff --raw when you want to see a summary of changes in a compact, machine-friendly format. It’s useful when you’re scripting or automating tasks around git, because it’s easier for a script to parse this raw format.
Keep in mind that the
git diff --raw output is designed to be compact and machine-readable. If you’re a human looking to understand changes in detail, you might find other options such as
git diff or
git diff --color-words more helpful, as they show added and removed lines in a more human-friendly way.