SlideShare une entreprise Scribd logo
1  sur  12
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 130test_content
The tree
tree [content size]0
10644 blob a906cb README
10755 blob 6f4e32 run
04000 tree 1f7a4e src
The commit
$ 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 <m.cupcic@criteo.com> 1380977766 +0200
committer Manu <m.cupcic@criteo.com> 1380977766 +0200

This is a commit message.
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.
Things we can play with
git reflog
git fsck

git pack
git config

git rebase -i
git reset
git refspecs
git stash

git add -p
git log (advanced stuff)

git pull –rebase

Contenu connexe

Similaire à Git internals

Git branching model_for_tap_team
Git branching model_for_tap_teamGit branching model_for_tap_team
Git branching model_for_tap_team
Grzegorz Wilczynski
 

Similaire à Git internals (20)

Git Tutorial Yang Yang
Git Tutorial Yang YangGit Tutorial Yang Yang
Git Tutorial Yang Yang
 
Git in action
Git in actionGit in action
Git in action
 
Six3 Getting Git
Six3 Getting GitSix3 Getting Git
Six3 Getting Git
 
Git
GitGit
Git
 
Git foundation
Git foundationGit foundation
Git foundation
 
Git branching model_for_tap_team
Git branching model_for_tap_teamGit branching model_for_tap_team
Git branching model_for_tap_team
 
Git: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commandsGit: An introduction of plumbing and porcelain commands
Git: An introduction of plumbing and porcelain commands
 
Git internals
Git internalsGit internals
Git internals
 
Git Basic
Git BasicGit Basic
Git Basic
 
Learning Basic GIT Cmd
Learning Basic GIT CmdLearning Basic GIT Cmd
Learning Basic GIT Cmd
 
git. WTF is it doing anyway?
git. WTF is it doing anyway?git. WTF is it doing anyway?
git. WTF is it doing anyway?
 
How git works
How git works  How git works
How git works
 
Understanding Git - GOTO London 2015
Understanding Git - GOTO London 2015Understanding Git - GOTO London 2015
Understanding Git - GOTO London 2015
 
Version Control and Git - GitHub Workshop
Version Control and Git - GitHub WorkshopVersion Control and Git - GitHub Workshop
Version Control and Git - GitHub Workshop
 
Git
GitGit
Git
 
Gittalk
GittalkGittalk
Gittalk
 
Knowledge is Power: Getting out of trouble by understanding Git - Steve Smith...
Knowledge is Power: Getting out of trouble by understanding Git - Steve Smith...Knowledge is Power: Getting out of trouble by understanding Git - Steve Smith...
Knowledge is Power: Getting out of trouble by understanding Git - Steve Smith...
 
Git使用
Git使用Git使用
Git使用
 
Did you git yet?
Did you git yet?Did you git yet?
Did you git yet?
 
Introducción a git y GitHub
Introducción a git y GitHubIntroducción a git y GitHub
Introducción a git y GitHub
 

Dernier

Dernier (20)

Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 

Git internals

  • 1.
  • 4. Git objects $ ls .git/ branches config description HEAD hooks index info logs objects refs
  • 5. 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 130test_content
  • 6. The tree tree [content size]0 10644 blob a906cb README 10755 blob 6f4e32 run 04000 tree 1f7a4e src
  • 7. The commit $ 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 <m.cupcic@criteo.com> 1380977766 +0200 committer Manu <m.cupcic@criteo.com> 1380977766 +0200 This is a commit message.
  • 8. 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
  • 9. 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'
  • 10. Git References $ git tag 1.0 dbaf944a4a9eb72af64042b1e3a128936000dfc2 $ cat .git/refs/tags/1.0 dbaf944a4a9eb72af64042b1e3a128936000dfc2
  • 11. 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.
  • 12. Things we can play with git reflog git fsck git pack git config git rebase -i git reset git refspecs git stash git add -p git log (advanced stuff) git pull –rebase

Notes de l'éditeur

  1. Internal model of the commit object.DEMO: git cat-file –p &lt;commit sha1&gt;
  2. The most important Git object is the COMMIT.The most important thing about the commit is that it is IMMUTABLE.So why is it important?A commit is primarily defined by 3 things: a snapshot of the working directory, the “disk” state ; a commit message ; and most importantly, a parent commit. Every commit has a pointer toward its parent. This is what defined a history of commits, a chained list of commit.So, if you change- a single file -&gt; different commit- the commit message -&gt; different commit- the commit parent or parents -&gt; different commitA commit is uniquely identified by its SHA1. A SHA1 is deterministic : a snapshot with the exact same content will have the same SHA1. A commit refering to the same snapshot, the same parent commit and the same commit message will be identified by the same SHA1.So why is this important?It matters because of the initial Git design choices. Git is primarily a content-addressables file that stores any version of any object as a distinct object accessible for ever. Any file, any snapshot, any commit that has been archived in Git, can be retrieved for ever by its SHA1.These files are stored entirely, all the time. This is a major difference with other versioning systems such as Subversion and Perforce, which stores diff of files.Now, I’m making simplifications, but this is true in a 1st approximation.Why do we care?This means that all snapshots that have been committed once can always be retrieved. Keep this in mind as it will be important later.
  3. Commit has a pointer to a tree, which describes the entire git repo content.