git diff --stat
is a handy command that provides a concise summary of what has changed between two states in a Git repository. The command shows the number of lines that have been added or deleted, and the overall amount of changes in each file.
Here’s a step-by-step guide to using git diff --stat
:
Step 1: Open your terminal.
Step 2: Navigate to your Git repository with the cd
command. For instance, if your Git repository is in a directory called “my-project”, you’d use the following command:
cd path/to/my-project
Step 3: To see a summary of changes made since the last commit, run the git diff --stat
command:
git diff --stat
This command compares the current, uncommitted state of your repository (the working tree and the staging area) to the last commit (HEAD). It outputs a list of files that have changed, along with the number of lines added or deleted in each.
The output might look something like this:
file1.txt | 4 ++--
file2.txt | 3 +++
2 files changed, 5 insertions(+), 2 deletions(-)
This means file1.txt
has had 2 lines added (shown by ++) and 2 lines removed (shown by –), while file2.txt
has had 3 lines added.
Step 4: To compare between two specific commits, use the git diff --stat <commit1>..<commit2>
syntax:
git diff --stat a1b2c3d..e4f5g6h
In this command, a1b2c3d
and e4f5g6h
are placeholders for the SHA-1 hashes that Git uses to identify commits. This command will show the summary of changes between these two commits.
Remember to replace a1b2c3d
and e4f5g6h
with the actual commit hashes from your Git log, which you can find using the git log
command.
git diff --stat
is a great way to quickly understand the scope and impact of changes made in a Git repository. However, keep in mind that it only provides a high-level summary. To see the actual line-by-line changes, you’d use the git diff
command without the --stat
option.