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 HEAD shows staged and unstaged changes together

Git
~/tips/tip-git-diff-head-all-changes

git diff HEAD

Compares your working tree with the last commit, staged or not.

A plain git diff hides what you already staged, and git diff --staged hides what you didn’t. For everything since the last commit, compare with HEAD.

git diff HEAD

This compares the files in your working tree with the last commit, no matter what’s in the index. A file you staged and then edited again shows up once, with all changes combined:

$ git diff --stat
 t1 | 1 +
$ git diff HEAD --stat
 t1 | 2 ++

The first only sees the unstaged line, the second sees both. That’s the full picture of what git commit -a would commit, apart from new untracked files.

I’d run it as a last review before a commit, so nothing you staged an hour ago comes as a surprise. It also works with any other commit, such as git diff HEAD~3 for everything since three commits back, uncommitted work included.

Leave out HEAD and the meaning changes completely, so don’t shorten it out of habit. And like every git diff, untracked files aren’t shown. Either stage them, or mark them with git add -N so they appear in the diff without staging their content.

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