Source: https://www.eliwhitney.org/
-
.tig/objects
holds revisions of the file. -
.tig/master
contains the latest revision filename:file.txt.v3
proj/ + .tig/ | + objects/ | | + file.txt.v1 | | + file.txt.v2 | | + file.txt.v3 | + master | + file.txt
-
Commit
-
Get the current revision from
.tig/master
-
Increment that by 1: 3 → 4.
-
Copy
file.txt
to.tig/objects/file.txt.v4
-
Set
.tig/master
tofile.txt.v4
-
-
Checkout
-
Get lastest revision from
.tig/master
-
Copy
.tig/objects/file.txt.v4
tofile.txt
-
-
Idea: Use SHA1 sum of the content to identify the file.
-
SHA1 is similar to checksum algorithms: but 20-bytes long
-
Interesting property, no two files will have the same checksum. (very low probability)
-
Depicted as a 40 digit hex number: 4c7be7b2c3641a5e489c4ce667699eeee4e994c9
-
Only first 6 digits are shown: 4c7be7…
proj/ + .tig/ | + objects/ | | + 4c7be7b2c3641a5e489c4ce667699eeee4e994c9 | | + c9360f5cd3d2c9f5656cd5ee10dedd3d235a4e0f | | + da39a3ee5e6b4b0d3255bfef95601890afd80709 | + master | + file.txt
-
Commit
-
Find SHA1 of
file.txt
:58f3966…
-
Store
file.txt
to.tig/objects/58f3966…
-
Set
.tig/master
to58f3966…
-
-
Checkout
-
Get lastest revision from
.tig/master
-
Copy
.tig/objects/58f3966…
tofile.txt
-
-
Commit object: meta information stored in the object database.
{ "log-msg": "Added goodbye world", "author": "[email protected]", "time": 1437790070, "content": eb12bc..., "parent": ef4d3e..., }
-
Stores log message, author, and time information as well.
-
Stores SHA1 of
file.txt
that corresponds to this commit. -
Stores SHA1 of parent commit.
-
Commit
-
Find SHA1 of
file.txt
:58f3966…
-
Store
file.txt
to.tig/objects/58f3966…
-
Create and store commit object:
8fb439…
-
Set
.tig/master
to commit object
-
-
Checkout
-
Get lastest commit object from
.tig/master
:8fb439…
-
Get content SHA1 from commit object:
58f3966…
-
Copy it to
file.txt
-
-
Log
-
Get lastest commit object from
.tig/master
:8fb439…
-
Print the commit info
-
Get the parent commit
-
Print the commit info
-
… Repeat …
-
-
.tig/master
: the latest version of the file. -
.tig/HEAD
: the current checked out version. -
Commits not allowed if not latest version
proj/ + .tig/ | + objects/ | | + 4c7be7b2c3641a5e489c4ce667699eeee4e994c9 | | + c9360f5cd3d2c9f5656cd5ee10dedd3d235a4e0f | | + da39a3ee5e6b4b0d3255bfef95601890afd80709 | + master | + HEAD | + file.txt
-
Checkout
-
Determine the commit SHA1.
-
If SHA1 specified, use it.
-
If not specifed get lastest commit object from
.tig/master
-
-
Get content SHA1 from commit object.
-
Copy it to
file.txt
-
Set
HEAD
to checked-out commit SHA1.
-
-
Commit
-
If
HEAD
!=master
, cannot commit. -
Find SHA1 of
file.txt
:58f3966…
-
Store
file.txt
to.tig/objects/58f3966…
-
Create and store commit object:
8fb439…
-
Set
.tig/master
to commit object
-
-
.tig/refs/heads
: contains one file per branch -
Name of the file, corresponds to named of the branch
-
Just like
master
contains the SHA1 of the latest commit in the branch -
.tig/HEAD
:-
Contains SHA1 if checkout done by SHA1
-
Contains the branch name if checkout done by branch name. Example:
ref: refs/heads/master
-
proj/ + .tig/ | + objects/ | | + 4c7be7b2c3641a5e489c4ce667699eeee4e994c9 | | + ... | + refs/ | + heads/ | + master | + 2.0-dev | + HEAD | + file.txt
-
Create Branch at commit
-
Store commit SHA1 in
ref: refs/heads/master
-
-
Checkout
-
Determine the commit SHA1:
-
If SHA1 specified, use it.
-
If branch specified, get SHA1 from
ref: refs/heads/your-branch
-
-
Get content SHA1 from commit object.
-
Copy it to
file.txt
-
Set
HEAD
:-
If checkout using SHA1, set to SHA1
-
If checkout using branch name, set to
ref: refs/heads/your-branch
-
-
-
Commit
-
If
HEAD
does correspond to a branch, cannot commit. -
Find SHA1 of
file.txt
:58f3966…
-
Store
file.txt
to.tig/objects/58f3966…
-
Create and store commit object:
8fb439…
-
Set
ref: refs/heads/your-branch
to commit object
-