Quick reference for Git commands and concepts while reading Pro Git.

General

Git was developed in 2005 by Linus Torvalds as an alternative to the proprietary BitKeeper version control system.

The major difference between Git and other VCS is how Git “thinks” about its data. Instead of storing information as a set of files and the changes made to each file over time (delta-based version control), Git thinks of its data like a stream of snapshots of a miniature filesystem.

If files have not changed, Git doesn’t store the file again, just a link to the previous identical file.

Most operations in Git need only local files. Also, everything in Git is checksummed before it is stored and then referred to by that checksum (an SHA-1 hash). This means we can’t use information in transit or get file corrupt without it getting detected.

Files tracked with Git have three states they can be in:

StateDescription
ModifiedFile has been changed but not commited yet
StagedMarks the current “version” of the file to go into the next commit snapshot
CommitedFile is stored in the Git repository
  • Working tree - a single checkout of one version of the project. The files are stored on the disk to use and modify
  • Staging area - a file, contained in the Git directory that stores information about what - this is where Git stores the metadata and object database for the porroject will go into the next commit
  • Git directory - this is where Git stores the metadata and object database for the project

Commands

CommandDescription
git diff --stagedShow diff for staged files