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:

  1. Show differences between index and working tree; that is, changes you haven’t staged to commit:
git diff [filename]
  1. 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]
  1. 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.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)