If I run git diff
I would expect to see a list of changes of my working directory relative to whatever had been committed before (or a list of the working direc
1.How, in plain English, does git diff work?
How git diff
works all depends on what parameters you pass to it.
Depending on the parameters, git diff
will show the changes between two commits, or between a commit and the working tree, etc...
For example, git diff
, git diff --staged
and git diff HEAD
are described further below.
2.How can I show a diff of all the changes I've made (unstaged and staged)?
By using both commands git diff HEAD
and git diff --staged
.
But in the case of a repository just created with git init
, the question doesn't really make sense and git diff HEAD
cannot be used: the history being empty, there's no commit and no HEAD
yet!
git diff
shows the changes in your working tree relative to the last commit, only for tracked files
git diff HEAD
shows the changes in your working tree relative to the last commit (includes files that are not tracked)
git diff --staged
(or its synonym git diff --cached
) shows the changes you staged for the next commit relative to the last commit
There are many other ways to invoke git diff
, for comparing arbitrary commits or branches, etc. Invoke git help diff
to read more about it.