{:check ["true"], :rank ["repository" "commits" "staging"]}
git
has a complex model in order to accommodate the many possible workflow
in code management.\$ cd <path to directory>
\$ git init
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│ └── ...
├── info
│ └── exclude
├── objects
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
9 directories, 16 files
Tree
We call a snapshot along the timeline in a versioning filesystem a tree.
Commit
A commit is a snapshot in the timeline. It has a tree as well as a unique identifier, known as its hashcode.
Repository
Commits in
.git/
Each commit is a tree.
Staging area
A delta tree that will be added to the HEAD to form the next commit.
Working directory
A normal UNIX directory for us to work with the files in the repository.
Definition
A commit a snapshot in a timeline.
Naming
Each commit has a unique identifier, known as its hash code. The hash code is derived from the contents of the files in the commit.
The full hash code is a 40-character long hex string:
6d9bb11bc195a0d928ac830886124b0c81d91bb8
. However, in practice, one can refer to a commit with a shorted prefix as long as the prefix can uniquly identify the commit. E.g.6d9b
is most likely sufficient to refer to the commit.
Parents
Each commit is derived from other commits:
- The initial commit does not have parents.
- Most commits have one parent.
- When we merge two branches, we create commits that have two parents.
Branch
Branches represent alternate timelines. A branch is a pointer to the latest commit in its timeline. As the timeline is extended with new commits, the pointer moves automatically. There is always the default
branch
, typically named themaster
branch.
Head
The commit that we focus on is called the
HEAD
. Think ofHEAD
as a pointer to any commit. But in normal workflow,HEAD
should be pointing to abranch
.
The Working Directory
We recall that the working directory is the normal filesystem directory that mirrors the content of some particular commit in the repository.
*
|
|
* =======> <working directory>
Staging
We can perform any modifications to the
<working directory>
. The modified working directory will be used to create a new commit in the branch. However, we cherrypick the changes made in the working directory to be included in the new commit.Picking changes to be included in the new commit is called staging.
*
|
|
* ==============> <working directory>
|
+---------+ | changes
| staging | <--+
| | | more changes
| | <--+
+---------+
Commit
Eventually, we are happy with the accumulation of changes in the staging area, and saves the snapshot of the repository as a new commit.
*
|
|
* ==============> <working directory>
| |
| +---------+ | changes
| | staging | <--+
| | | | more changes
| | | <--+
| +---------+
| |
| |
* <------+ commit