git diff --stat command in Git is a powerful tool that gives you a brief summary of changes between two states of your project, typically used to see what you have modified compared to the last commit. It’s a variant of the
git diff command that provides a summarized view of the changes, showing only the number of line changes (additions and deletions) for each file, rather than showing the actual line-by-line changes.
When you run the
git diff --stat command, Git responds with output that looks something like this:
file1.txt | 2 ++ file2.txt | 5 +++-- file3.txt | 1 - 3 files changed, 5 insertions(+), 3 deletions(-)
In this example,
file1.txt has had two lines added (represented by
file2.txt has had three lines added and two removed (represented by
5 +++--), and
file3.txt has had one line removed (represented by
1 -). The summary at the end tells you that there have been changes in 3 files with 5 insertions and 3 deletions.
git diff --stat is particularly useful when you have a large number of changes across many files and want to get a high-level overview of those changes without scrolling through potentially hundreds of lines of diffs.
It’s important to note that
git diff --stat operates on the unstaged changes by default. If you want to see the difference between the staged changes and the last commit, you should use
git diff --staged --stat.
git diff --stat is an excellent way to quickly and easily see where you’ve made changes in your project, without getting bogged down in the specifics of those changes. It’s one of many tools Git provides to help you manage and understand your codebase.