Reputation: 1217
I have 3 files, A, B, C.
I made some changes to A and B and then ran git diff
to check the changes I made. Everything looked good. Then I made a change to 'C' and ran git diff
again but this time it shows only the changes I made to 'C'. If I type git diff HEAD
then I can see the changes to all 3 files.
What's gonna happen when I commit? Will it commit only the changes to C or A, B, C?
Upvotes: 0
Views: 63
Reputation: 8169
You added A and B via git add
. If you run git diff
after staging filex for the next commit, you won't see the changes. This is the expected behaviour, and you can run git diff --cached
to see the changes to the added files.
If you the modify another file, C, git diff
will show only the changes in C (unstaged yet).
The command git diff HEAD
shows the changes for both staged and unstaged files: exactly, it shows the changes in the working tree since your last commit.
To answer briefly to your original question, git commit
will commit the changes to all the files you modified (A, B, C), and not only C.
Upvotes: 1
Reputation: 361556
If you git add
ed A and B to the index, you can do git diff --cached
to see their changes. git diff
only shows unstaged changes. Quoth the git diff man page:
Various ways to check your working tree
$ git diff (1)
$ git diff --cached (2)
$ git diff HEAD (3)
1. Changes in the working tree not yet staged for the next commit.
2. Changes between the index and your last commit; what you would be committing
if you run "git commit" without "-a" option.
3. Changes in the working tree since your last commit; what you would be
committing if you run "git commit -a"
Ultimately, you should also use git status
before you commit to see what exactly you'll be committing.
Upvotes: 2