In general, git diff
compares just two things. (The exceptions do not apply here.) You pick which two things, and Git gives you a set of instructions, e.g.:
- take out this line at this location
- put in this other line at this other location
that will, if you follow them, transform the first thing into the second thing.
In this particular case, the two things you selected with:
git diff test.js
are the version of test.js
that is in the index, and the version of test.js
that is in the work-tree. Neither of these is necessarily in any branch (though, of course, either or both versions could match some version(s) of some file(s) in some other branch(es)).
The short description of the work-tree is simple enough: it's where you work on your files. Files stored inside Git are in a Git-only format, so for the other programs on your computer to use them, you need to have them in a place you can work on them. That's the work-tree.
The short description of the index is that it is where you have Git build up your next commit. It starts out matching your current commit, from your current branch; when you git add
a file, that copies the file from the work-tree into the index, so that it's ready to go into the next commit.
To read more about what Git's index and work-tree are and do, see Difference between HEAD / Working Tree / Index in Git.