Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subsequent changes to file after "git add"

Tags:

git

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?

like image 717
nom-mon-ir Avatar asked Aug 06 '11 22:08

nom-mon-ir


People also ask

Can I make changes after git add?

In git, files (per se) aren't staged, changes are. So when you do git add <filename> , it is the current state of that file that is staged. If you change the file and want to add those changes as well, you just do another git add .

What is the next step after git add?

When you're ready to save a copy of the current state of the project, you stage changes with git add . After you're happy with the staged snapshot, you commit it to the project history with git commit . The git reset command is used to undo a commit or staged snapshot.

How do I see changes after git add?

Without further options, "git diff" will show us all current local changes in our working copy that are unstaged. If you want to see only changes that have already been added to the Staging Area, "git diff --staged" is your command of choice.

How do you stage all changes?

So the command to stage all changes for git is git add -A .


1 Answers

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.

like image 177
svick Avatar answered Oct 18 '22 19:10

svick