![](https://csdnimg.cn/release/download_crawler_static/10941479/bg14.jpg)
For example, to browse the history of the project, Git doesn’t need to go out to the server to get the
history and display it for you — it simply reads it directly from your local database. This means you
see the project history almost instantly. If you want to see the changes introduced between the
current version of a file and the file a month ago, Git can look up the file a month ago and do a local
difference calculation, instead of having to either ask a remote server to do it or pull an older
version of the file from the remote server to do it locally.
This also means that there is very little you can’t do if you’re offline or off VPN. If you get on an
airplane or a train and want to do a little work, you can commit happily (to your local copy,
remember?) until you get to a network connection to upload. If you go home and can’t get your VPN
client working properly, you can still work. In many other systems, doing so is either impossible or
painful. In Perforce, for example, you can’t do much when you aren’t connected to the server; in
Subversion and CVS, you can edit files, but you can’t commit changes to your database (because
your database is offline). This may not seem like a huge deal, but you may be surprised what a big
difference it can make.
Git Has Integrity
Everything in Git is checksummed before it is stored and is then referred to by that checksum. This
means it’s impossible to change the contents of any file or directory without Git knowing about it.
This functionality is built into Git at the lowest levels and is integral to its philosophy. You can’t lose
information in transit or get file corruption without Git being able to detect it.
The mechanism that Git uses for this checksumming is called a SHA-1 hash. This is a 40-character
string composed of hexadecimal characters (0–9 and a–f) and calculated based on the contents of a
file or directory structure in Git. A SHA-1 hash looks something like this:
24b9da6552252987aa493b52f8696cd6d3b00373
You will see these hash values all over the place in Git because it uses them so much. In fact, Git
stores everything in its database not by file name but by the hash value of its contents.
Git Generally Only Adds Data
When you do actions in Git, nearly all of them only add data to the Git database. It is hard to get the
system to do anything that is not undoable or to make it erase data in any way. As with any VCS, you
can lose or mess up changes you haven’t committed yet, but after you commit a snapshot into Git, it
is very difficult to lose, especially if you regularly push your database to another repository.
This makes using Git a joy because we know we can experiment without the danger of severely
screwing things up. For a more in-depth look at how Git stores its data and how you can recover
data that seems lost, see Undoing Things.
The Three States
Pay attention now — here is the main thing to remember about Git if you want the rest of your
learning process to go smoothly. Git has three main states that your files can reside in: committed,
modified, and staged:
15