Lars
Lars

Reputation: 8458

What is Git actually doing when I run git diff

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.

Upvotes: 0

Views: 78

Answers (3)

LeGEC
LeGEC

Reputation: 51780

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.

Upvotes: 0

Kornel
Kornel

Reputation: 100080

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.

Upvotes: 3

Claudio
Claudio

Reputation: 10947

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

Upvotes: 0

Related Questions