0

As a newcomer to Git, can somebody please explain in relatively simple terms what git diff actually does, without going into branching/merging etc?

From my experience I know the outcome of running it: Any files in my working directory that are different to those in my repo will be returned by git diff AS LONG AS they have not been put in the staging index.

If all my changes have been put in the staging index, git diff will return nothing. To see my changes, I have to use git diff --staged.

Is there a simple way to some this up? I can't quite get my head around the caveat about the staging index.

Lars
  • 7,908
  • 11
  • 52
  • 70
  • You have very good explanations in the answers for the question http://stackoverflow.com/questions/1587846/how-do-i-show-the-changes-which-have-been-staged – cexbrayat May 22 '13 at 13:33

3 Answers3

3

You're right, git diff shows unstaged changes.

Technically it's a difference between working tree and index tree (which, when nothing is staged, is identical to HEAD's tree, i.e. last commit).

And 'tree' in git-speak is a snapshot of files in a directory.

Kornel
  • 97,764
  • 37
  • 219
  • 309
0

My suggestion is to read this book (freely available): http://git-scm.com/book

Claudio
  • 10,614
  • 4
  • 31
  • 71
0

You can read the manual. The "Description" part explains all the variations on git diff, git diff --cached, git diff commit1 commit2, etc...

I would suggedt using git status to have a clear picture of the state of your files.

You can then use git diff HEAD -- <path/to/file> to view the differences between a file in its current state and the last commited version.

LeGEC
  • 46,477
  • 5
  • 57
  • 104