brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git diff with dirstat shows which folders a change touched most

Git
~/tips/tip-git-diff-dirstat-folders

git diff --dirstat main...HEAD

Gives a percentage per folder, so you see where a big change really happened.

For a big branch, --stat gives you two hundred lines of files. I’d rather see the folders first.

git diff --dirstat main...HEAD

Instead of listing files, git adds up the changes per directory and prints a percentage for each:

  83.6% src/api/
  16.3% vendor/

That tells you straight away whether a pull request is mostly real code or mostly a vendored library and generated files. By default the percentages are based on the amount of changed lines, and folders under 3% are left out to keep the list short.

You can change both. files counts changed files instead of lines, and a number at the end sets the cutoff:

git diff --dirstat=files,0 main...HEAD

With a cutoff of 0, every folder shows up. git log --dirstat and git show --dirstat take the same option, so you can do it for a single commit too.

The numbers count changes, not importance. A one-line fix in an auth check shows up as almost nothing next to a reformatted CSS folder. I’d use dirstat to decide where to start reading, not to decide what matters. Also, changes in a subfolder count toward its parent too unless you add noncumulative, so the totals can pass 100%.

Further reading: git-diff documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link