git internals
TRANSCRIPT
![Page 1: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/1.jpg)
![Page 2: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/2.jpg)
internals
![Page 3: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/3.jpg)
Git Objects
![Page 4: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/4.jpg)
Git objects
$ ls .git/
branches
config
description
HEAD
hooks
index
info
logs
objects
refs
![Page 5: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/5.jpg)
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
![Page 6: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/6.jpg)
The tree
tree [content size]\010644 blob a906cbREADME10755 blob 6f4e32run04000 tree 1f7a4e src
![Page 7: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/7.jpg)
$ 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
![Page 8: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/8.jpg)
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
![Page 9: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/9.jpg)
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'
![Page 10: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/10.jpg)
Git References
$ git tag 1.0
dbaf944a4a9eb72af64042b1e3a128936000dfc2
$ cat .git/refs/tags/1.0
dbaf944a4a9eb72af64042b1e3a128936000dfc2
![Page 11: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/11.jpg)
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.
![Page 12: Git internals](https://reader035.vdocuments.us/reader035/viewer/2022062319/554f5865b4c905524c8b533d/html5/thumbnails/12.jpg)
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