Wednesday 14th January 2009
Note that git differs from some other version control systems in the way it treats the working directory, index and commits.
First of all, the stuff in the working tree that isn't in the index (the stuff we're not going to commit), but isn't explicitly ignored, is said to be in limbo. Exactly what is in limbo, and what's actually in the index can be confusing if you're not clear on what's actually go on when you add and commit files.
Let's try an example. Say we have a file, foo, which has already been committed. Let's label the current content of foo as foo.1 (note that this is not what git calls it - this is just to make this explanation a little easier). We then make some changes to foo. We'll call the updated content foo.2. If we run the command:
git will say there's nothing to commit, since we haven't actually added anything to the index. We can either use git commit -a to add and commit the change in one, but let's say we just add it using:
git add foo
Now, foo.2 is in the index, but hasn't been committed. We might then make further changes to foo, meaning the content is now foo.3. Without any calls to git add, we call
and git updates foo in the repository. Note, however, that this committed foo.2 to the repository, not foo.3, since we never actually added foo.3 to the index. The changes between foo.2 and foo.3 are still in limbo. If we wanted to commit the latest revision of foo to the repository, we would have to have added foo again just before committing.
Each time you successfully run a commit command, git creates a new commit for whatever branch you're working in (more on branches later). Each commit is uniquely identifiable by a SHA1 hash. When referencing individual commits, you can use this SHA1 hash. In fact, you don't even need to use the entire hash - just enough characters to uniquely identify that commit.
The latest commit of a branch is always know as HEAD.
Appending a caret to the identifier of a commit will refer to the commit's parent. For instance, HEAD^ refers to the commit before last.