The index can be thought of as the set of intended modifications. A commit is a two-step process: the changes are staged, and then committed.
It's All About the Index
Linus Torvalds argued on the Git mailing list that Git cannot be appreciated without understanding the purpose of the index. The state of the index can be queried at any time using git status.
File Classifications in Git
Git classifies your files into three groups: tracked, ignored, and untracked.
Tracked files are those already in the repository on staged in the index.
Ignored files are explicitly declared invisible even though they are in the working directory.
Untracked files are files not in the previous two categories.
To make Git ignore a file within a directory, simply put that file's name to the file .gitignore. Even though .gitignore is a special file to Git, it is managed by Git like any other file and needs to be staged and committed like any other.
A file that is untracked is converted to tracked by git add. git add casues the file to be copied into the object store and indexed by its resulting SHA1 value. Staging a file is also called caching a file or putting a file in the index.
Using git rm
The git rm command is the inverse of git add. To remove a file from the working directory that has not been staged, the normal rm command can be used. git rm --cached removes a file from the index and leaves it in the working directory. git rm removes the file from both the index and the working directory.
The .gitignore File
A .gitignore file can contain a list of filename patterns that specify what files to ignore. A directory name is marked by a trailing slash character (/). A pattern containing shell globbing characters such as * are expanded as shell glob patterns. An asterisk can only match a single file or directory name. An exclamation point inverts the sense of the pattern on the rest of the line.
.gitignore files can also be present in any directory within the repository, and each will affect its directory as well as all subdirectories of that one. The rules also cascade and can be overrided by more local .gitignores.
A Detailed View of Git's Object Model and Files
What the commit does: first the virtual tree object that is the index is converted to a real tree object and placed in the object store under its SHA1 value. Second, a commit object is created with the log message, and this commit points to the new tree object and also the previous commit. This, the branch ref is moved from the most recent commit to the newly created commit object, becoming the new branch HEAD.
Article notes
In Git, what can be thought of as the set of intended modifications?
The index
Linus Torvalds once argued on the Git mailing list that Git cannot be appreciated without understanding the purpose of what?
The index
What are you querying the state of when using the git status command?
The index
What command can be used to query the state of the Git index at any time?
git status
What are the three categories that Git classifies your files into?
Tracked, ignored, untracked
Git considers files that are already in the repository or staged in the index to be what?
Tracked
Git considers files that are explicitly declare invisible to be what?
Ignored
Git considers files that are not in the repository or staged, and also not being explicitly ignored, to be what?
Untracked
What Git command converts an untracked file to a tracked one?
git add
What is the special file to Git that is used to declare what files are to be ignored?
.gitignore
What command is the inverse of git add?
git rm
What is the Git command to remove a file from the index, but leave it in the working directory?
git rm --cached
What is the Git command to remove a file from the index and also remove it from the working directory?
git rm
What is the command to remove a file that has not been staged from the working directory?
rm
In a .gitignore file, what marks a directory name?
A trailing slash (/)
What converts the virtual tree object that is in the Git index to a real tree object placed in the object store under its SHA1 value, as well as creates a commit object pointing to the tree and previous commit(s)?
A commit