Git internals

Time to learn a bit more than the bare basics of git?

Some notes taken when reading:

Git is a simple key-value data store.

Create empty git repo:

mkdir git-test
cd git-test
git init
Initialized empty Git repository in /tmp/test/.git/

# List all files and folders etc.
find .git/objects

# Search for regular files
find .git/objects -type f

Store some content:

echo 'test content' | git hash-object -w --stdin

Git returns the key for the object created, the so called checksum hash.

The object has been stored in a file:

find .git/objects -type f 

Cat the contents of the file:

git cat-file -p d670460b4b4aece5915caf5c68d12f560a9fe3e4
test content

Store content i a ordinary file:

echo 'version 1' > test.txt
git hash-object -w test.txt 

Update with new version:

echo 'version 2' > test.txt
git hash-object -w test.txt 

List the files:

find .git/objects -type f 

Revert to old version:

git cat-file -p 83baae61804e65cc73a7201a7252750c76066a30 > test.txt 
cat test.txt 
version 1

Go back to new version:

git cat-file -p 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a > test.txt 
cat test.txt 
version 2

Show the object type using the hash:

git cat-file -t 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a

Add a file and show the tree

git add *
git commit -a -m "initial commit"

git cat-file -p master^{tree}
100644 blob 1f7a7a472abf3dd9643fd615f6da379c4acb3e3a	test.txt