The git book defines the git index:
The Git index is used as a staging area between your working directory and your repository. You can use the index to build up a set of changes that you want to commit together. When you create a commit, what is committed is what is currently in the index, not what is in your working directory.
But I am still having a difficult time understanding it, especially the highlighted statement that "what's committed is not what's in my working directory".
So far, in my limited working with git, everything in the working directory is always committed, if I do:
git add <all new files in the working directory>
git commit -a -m "git will refuse to commit without this comment"
git then commits all modified files as well as all new files.
So, in effect, my working directory is the staging area?
I am not sure then what the git index
is and how it is interpreted as the staging area.
Could you please explain?
The answer in your particular case is that you are understanding the documentation correctly, but using the "shortcut" command to commit your entire working directory.
If you run git commit -a -m "Message"
then your working directory is treated like it is the staging area. This is convenient sometimes, but you lose the ability to use the index as designed. Try the following command:
git commit -m "Message"
If you do this instead, you can use the staging area to commit only part of the changes you have made to your working directory.