tags:

views:

67

answers:

3

Hi,

I was wondering if I can see the changes that were made to a 'file' after I have done git add 'file'

That is, when I do:

git add file
git diff file

no diff is showed... But I guess there's a way to see the differences since the last commit.

Any ideas ?

Thanks,

A

A: 

try git diff HEAD file ?

See the EXAMPLE section under git-diff(1)

J-16 SDiZ
A: 

Of course you can't see anything, the file was just added: git doesn't have any history of that file so it can't diff it against nothing. Even when you commit, the file is also just added, so when you diff you'll get nothing.

What you need is "status"

git status

to see what files have been added, removed modified or with unknown status.

FearUs
That's not the reason. This will happen even for a file that has been around for a long time. The real reason it happens is because when you stage the file, diff will be comparing it against the latest thing in the index which is -- the stage! It will always be identical to itself. The --cached flag tells it to diff it with the cached contents from HEAD.
Adrian Petrescu
Do you really think that a full diff of 3 newly added files, each one of them is 100 lines of code is better than a status ?? He will get the same result: diff=300+ lines, status: 3 lines!
FearUs
@FearUs He's not talking about brand new files. He's talking about files whose changes have been staged with `git add`.
Nick Lewis
+3  A: 

You can show changes that have been staged with the --cached flag:

$ git diff --cached
mipadi
thank ! i had forgotten the --cached option... just what I needed : )
arod