Executing this command will change the content of the
diff_test.txt file. Once modified, we can view a diff and analyze the output. Now executing
git diff will produce the following output:
Let us now examine a more detailed breakdown of the diff output.
This line displays the input sources of the diff. We can see that
b/diff_test.txt have been passed to the diff.
This line displays some internal Git metadata. You will most likely not need this information. The numbers in this output correspond to Git object version hash identifiers.
These lines are a legend that assigns symbols to each diff input source. In this case, changes from
a/diff_test.txt are marked with a
--- and the changes from
b/diff_test.txt are marked with the
The remaining diff output is a list of diff 'chunks'. A diff only displays the sections of the file that have changes. In our current example, we only have one chunk as we are working with a simple scenario. Chunks have their own granular output semantics.
The first line is the chunk header. Each chunk is prepended by a header enclosed within
@@ symbols. The content of the header is a summary of changes made to the file. In our simplified example, we have -1 +1 meaning line one had changes. In a more realistic diff, you would see a header like:
In this header example, 6 lines have been extracted starting from line number 34. Additionally, 8 lines have been added starting at line number 34.
The remaining content of the diff chunk displays the recent changes. Each changed line is prepended with a
- symbol indicating which version of the diff input the changes come from. As we previously discussed,
- indicates changes from the
a/diff_test.txt and + indicates changes from