internals
Git Objects
Git objects
$ ls .git/
branches
config
description
HEAD
hooks
index
info
logs
objects
refs
The blob
$ git init
Initialized empty Git repository in /tmp/test/.git/
$ echo "test_content" | git hash-object -w -t blob --stdin
915e94ff1ac3818f1e458534b0228a12a99cd6c5
$ ls .git/objects/91/5e94ff1ac3818f1e458534b0228a12a99cd6c5
.git/objects/91/5e94ff1ac3818f1e458534b0228a12a99cd6c5
$ cat .git/objects/91/5e94ff1ac3818f1e458534b02* | zlib_inflate -d
blob 13\0test_content
The tree
tree [content size]\010644 blob a906cbREADME10755 blob 6f4e32run04000 tree 1f7a4e src
$ git commit file
[master dbaf944] This is a commit message.
$ cat .git/objects/db/af944a4a9eb72af64042b1e3a128936000dfc2 |
zlib_inflate -d
commit 318
tree 47ec7a250164a21cb14eb64618c3a903db0b7420
parent 402b26df0644f09fc62842c0a4a44a0a3345c530
author Manu <[email protected]> 1380977766 +0200
committer Manu <[email protected]> 1380977766 +0200
This is a commit message.
It explains what the hell this commit is about
The commit
The commit
• Is identified by• a snapshot of the repo state (the tree).• parent commit(s)• a commit message
• Is immutable• Has a deterministic hash (SHA1)• Commits form a linked list: the history
Git References
$ cat .git/refs/heads/master
dbaf944a4a9eb72af64042b1e3a128936000dfc2
$ cat .git/HEAD
ref: refs/heads/master
$ echo "dbaf944" > .git/refs/heads/newbranch
$ git checkout newbranch
Switched to branch 'newbranch'
Git References
$ git tag 1.0
dbaf944a4a9eb72af64042b1e3a128936000dfc2
$ cat .git/refs/tags/1.0
dbaf944a4a9eb72af64042b1e3a128936000dfc2
Take home message
• Git stores a snapshot of the whole repo at each commit.
• The SHA1 of a commit depends only on its content,
message, committer and parent(s).
• A git branch/tag is a 40 digits hex number stored in a
file.
git pull –rebase
git stash
git rebase -i
git pack
git config
git refspecs
git refloggit fsck
git log (advanced stuff)
git add -p
git reset
Things we can play with