How can I see what has changed in a file before committing to git?
You're looking for
git diff --staged
Depending on your exact situation, there are three useful ways to use git diff
:
- Show differences between index and working tree; that is, changes you haven't staged to commit:
git diff [filename]
- Show differences between current commit and index; that is, what you're about to commit (
--staged
does exactly the same thing, use what you like):
git diff --cached [filename]
- Show differences between current commit and working tree:
git diff HEAD [filename]
git diff
works recursively on directories, and if no paths are given, it shows all changes.
Use git-diff
:
git diff -- yourfile