nom-mon-ir
nom-mon-ir

Reputation: 3918

Subsequent changes to file after "git add"

git newbie here, bear with me if this is trivial. I cannot find this in some git basic docs seen so far.

I did a "git add file1" which puts the file into the index. Immediately after this the "git diff --cahced" shows correct diff content.

Then I made some more changes to file1. Now "git diff --cached" shows the previously shown diff content, and new changes are not being displayed. This makes me believe that the index is having the snapshot of the file1 contents when I did the "git add", in other words, when I staged the file.

Is this correct? And will subsequent commit will only commit what "git diff --cached" is showing me, or all my changes till the commit is issued?

Upvotes: 10

Views: 1806

Answers (1)

svick
svick

Reputation: 244848

That's the whole point of index – it contains changes to be commited. If you don't use -a, git commit will create a commit whose content (the tree) will be what was in the index.

What git add does is that is copies the file (or directory) from the working copy into the index.

One way this can be useful is git add -p: it lets you see changes to a file and adds a version of the file with only changes you chose to the index.

Upvotes: 5

Related Questions