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 --staged shows what your commit will contain

Git
~/tips/tip-git-diff-staged

git diff --staged

Shows the changes that are staged and will go into your next commit.

Plain git diff has a blind spot that catches people out. Once you stage a change, it disappears from the output.

That is because git diff compares your working tree with the staging area. If everything is staged, it shows nothing, and it looks like you have no changes. To see the staged part, ask for it:

git diff --staged

This compares the staging area with your last commit, so it shows exactly what git commit would record right now. --cached does the same thing; the docs say --staged is a synonym.

I would make it a habit to run it just before committing. It is the cheapest review you will get. A stray debug line or a half-finished edit is easy to spot when it is the only thing on your screen.

git diff is what is not staged yet, git diff --staged is what is. Together they cover everything in your tracked files that differs from HEAD.

The caveat: untracked files appear in neither, because git has no earlier version to compare them with. git status is where you see those.

Further reading: git diff documentation, On this site: unstage a file with git restore –staged, On this site: stage only part of a file with git add -p, On this site: Guide: let git bisect find the commit that broke your code

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