git commands
git diff
Show what changed: in the working tree, in what is staged, or between two commits or branches.
git diffAngle brackets are yours to fill in. Windows, Linux, macOS.
Examples for git diff
See what is staged for the next commit
git diff --stagedA plain git diff shows only unstaged changes, so once you git add a file it seems to disappear. --staged shows what the commit will contain.
gittooldiffsubcommand--stagedflagCompare your branch with main
git diff main...HEADThree dots compare against the point where your branch left main, so you see only your branch's changes, as a pull request shows them. Two dots compare the two tips directly, which also shows main's new commits in reverse.
gittooldiffsubcommandmain...HEADsince your branch left mainList only the files that changed
git diff --name-only <commit>Prints one path per line, which is easy to pass to another command. Use --stat to also see how many lines changed in each.
gittooldiffsubcommand--name-onlyflag<commit>argumentSee the changes to one file
git diff -- <path>Limits the diff to <path>. The -- separates paths from commits and branches, so a file named like a branch is not misread.
gittooldiffsubcommand--flag<path>pathIgnore whitespace changes
git diff -wHides lines whose only change is spaces or tabs, so reindented code does not hide the real change.
gittooldiffsubcommand-wflag
Flags
- --staged --cached
- Show what is staged, which is what the next commit will contain.
- --stat
- Show only the changed files and how many lines each gained and lost.
- --name-only
- Show only the names of the changed files.
- --word-diff
- Mark changed words inside a line, instead of whole lines.
- --ignore-all-space -w
- Ignore whitespace changes, such as reindentation.