Your SlideShare is downloading. ×
0
GIT Internals
Pedro Melo <{mailto,xmpp}:melo@simplicidade.org>
A short GIT History
• 2002 Apr 2005: The BitKeeper Wars
• Apr 2005: Episode IV - A New Hope
• July 2005: Hamano is the new...
on
 A short GIT History
 Person al take



• 2002 Apr 2005: The BitKeeper Wars
• Apr 2005: Episode IV - A New Hope
• July ...
GIT rules (without !!)
• Track content, not changes
• Simple repository
• Complex software
• Its easier to update the soft...
In other words, I'm right. I'm
always right, but sometimes
I'm more right than other
times. And dammit, when I say
"files d...
Strong Points

• Non-Linear development
• Distributed Development
 • Centralized development is a subcase
• Efficiency
• To...
Objects
• Git repositories store objects
• Stored in the Object Database
• Inside the Git directory
 • .git at the root of...
The Blob


• Files are stored as blobs
• Only content, no metadata
Meet the blob

blob [content_size]0
Your content goes here after the header

I like pizza with apples
The tree

• Trees store directories
• Mode, type, pointer and name
• Recursive, trees can contain trees
• Stored as a simp...
Meet the tree
tree [content_size]0
100644 blob b5f21a README
100644 blob afe433 Makefile.PL
040000 tree a42cd0 lib
The commit

• The object that makes history
• Pointer to a tree and the parent(s)
  commits if any
• Author, committer and...
Meet the commit...
commit [content_size]0
tree 23edfc
author Pedro Melo <melo@mini.me> 1243036800
committer Pedro Melo <me...
...and its child the other
              commit
commit [content_size]0
tree fde45c
parent 3454df
author Pedro Melo <melo@m...
The tag

• A name for a particular commit
• Can contain a message
• Optionally GPG signed
 • Allows for cryptographically ...
Meet the tag
tag [content_size]0
object 123fec
type commit
tag v1
tagger Pedro Melo <melo@mini.me> 1243037423

made it to ...
Git Data Model Recap

• Immutable objects
• A file per object
• Repacked into object packs for efficiency
• Organized as a d...
proj/
 Makefile.PL
 lib/
   Cool.pm
proj/
 Makefile.PL
 lib/
   Cool.pm
proj/
           Makefile.PL
           lib/
             Cool.pm




Cool.pm
proj/
           Makefile.PL
           lib/
             Cool.pm




Cool.pm
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL
   lib/




 Cool.pm
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL
   lib/




 Cool.pm
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL
   lib/




 Cool.pm
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL
   lib/




 Cool.pm
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL   Makefile.PL
   lib/         lib/...
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL   Makefile.PL
   lib/         lib/...
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL   Makefile.PL
   lib/         lib/...
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL   Makefile.PL
   lib/         lib/...
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL   Makefile.PL    Makefile.PL
   lib...
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL   Makefile.PL    Makefile.PL
   lib...
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL   Makefile.PL    Makefile.PL
   lib...
References
• “Names” for commits
• Mutable, they point to a specific commit
  and move to a new one after each
  commit



...
proj/
              Makefile.PL
              lib/
                Cool.pm




Makefile.PL   Makefile.PL    Makefile.PL
   lib...
master   HEAD
master   HEAD
master   HEAD

 test
master

 test    HEAD
master




 test    HEAD
master   HEAD




 test
test   master


          HEAD
test   master
           Merge
test
                Merge




       master
test   master
           Rebase
master
           Rebase




test
master
           Rebase




test
Rebase + Merge




          master
           test
Rebase + Merge




          master
           test
Non-SCM uses for Git
• Leverage strengths
 • immutable
 • over network pulls only missing objects
 • fast checkout (compar...
Beware of weak points

• Always stores full copy of files
 • not good for backups of DB dumps
• Full history more disk spac...
Content distribution
• Updates done in a master, central
  repository
• Hierarchy of slave repositories
• Fast sync betwee...
Read-only filesystem
• Design web server that fetch objects
  directly from the object database
• Compact storage, efficient...
Wiki/Ticketing backend

• Use git repository as storage for wiki or
  ticketing systems
• Good match for distributed devel...
That’s all folks!
• I’ll be around #codebits, feel free to ask me
  stuff
• If you want a git as a SCM demo, lets get
  or...
About Git
                         http://git-scm.com/
  Git Internals: http://peepcode.com/products/git-internals-pdf
   ...
Git Internals
Upcoming SlideShare
Loading in...5
×

Git Internals

3,374

Published on

An explanation about the organization of a Git repo, the type of objects it contains inside and the relations between them.

Published in: Technology, News & Politics
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,374
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
78
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Git Internals"

  1. 1. GIT Internals Pedro Melo <{mailto,xmpp}:melo@simplicidade.org>
  2. 2. A short GIT History • 2002 Apr 2005: The BitKeeper Wars • Apr 2005: Episode IV - A New Hope • July 2005: Hamano is the new maintainer • Late 2008: GitHub hits the spotlight “I’m an egotistical bastard, and I name all my projects after myself. First Linux, now git.” – Linus
  3. 3. on A short GIT History Person al take • 2002 Apr 2005: The BitKeeper Wars • Apr 2005: Episode IV - A New Hope • July 2005: Hamano is the new maintainer • Late 2008: GitHub hits the spotlight “I’m an egotistical bastard, and I name all my projects after myself. First Linux, now git.” – Linus
  4. 4. GIT rules (without !!) • Track content, not changes • Simple repository • Complex software • Its easier to update the software, complex to update all the repos so far Git Mantra: http://bit.ly/git-phylosophy
  5. 5. In other words, I'm right. I'm always right, but sometimes I'm more right than other times. And dammit, when I say "files don't matter", I'm really really Right(tm). Linus
  6. 6. Strong Points • Non-Linear development • Distributed Development • Centralized development is a subcase • Efficiency • Toolkit Design
  7. 7. Objects • Git repositories store objects • Stored in the Object Database • Inside the Git directory • .git at the root of your project • Four major object types • Objects are compressed for storage (zlib) • SHA1 of header+content ID
  8. 8. The Blob • Files are stored as blobs • Only content, no metadata
  9. 9. Meet the blob blob [content_size]0 Your content goes here after the header I like pizza with apples
  10. 10. The tree • Trees store directories • Mode, type, pointer and name • Recursive, trees can contain trees • Stored as a simple text file
  11. 11. Meet the tree tree [content_size]0 100644 blob b5f21a README 100644 blob afe433 Makefile.PL 040000 tree a42cd0 lib
  12. 12. The commit • The object that makes history • Pointer to a tree and the parent(s) commits if any • Author, committer and commit message
  13. 13. Meet the commit... commit [content_size]0 tree 23edfc author Pedro Melo <melo@mini.me> 1243036800 committer Pedro Melo <melo@mini.me> 1243036800 commit without a parent usually called first commit
  14. 14. ...and its child the other commit commit [content_size]0 tree fde45c parent 3454df author Pedro Melo <melo@mini.me> 1243036932 committer Pedro Melo <melo@mini.me> 1243036932 and we fixed that nasty bug after all, they do tend to crop up
  15. 15. The tag • A name for a particular commit • Can contain a message • Optionally GPG signed • Allows for cryptographically secure releases
  16. 16. Meet the tag tag [content_size]0 object 123fec type commit tag v1 tagger Pedro Melo <melo@mini.me> 1243037423 made it to 1.0!
  17. 17. Git Data Model Recap • Immutable objects • A file per object • Repacked into object packs for efficiency • Organized as a directed acyclic graph
  18. 18. proj/ Makefile.PL lib/ Cool.pm
  19. 19. proj/ Makefile.PL lib/ Cool.pm
  20. 20. proj/ Makefile.PL lib/ Cool.pm Cool.pm
  21. 21. proj/ Makefile.PL lib/ Cool.pm Cool.pm
  22. 22. proj/ Makefile.PL lib/ Cool.pm Makefile.PL lib/ Cool.pm
  23. 23. proj/ Makefile.PL lib/ Cool.pm Makefile.PL lib/ Cool.pm
  24. 24. proj/ Makefile.PL lib/ Cool.pm Makefile.PL lib/ Cool.pm
  25. 25. proj/ Makefile.PL lib/ Cool.pm Makefile.PL lib/ Cool.pm
  26. 26. proj/ Makefile.PL lib/ Cool.pm Makefile.PL Makefile.PL lib/ lib/ Cool.pm
  27. 27. proj/ Makefile.PL lib/ Cool.pm Makefile.PL Makefile.PL lib/ lib/ Cool.pm
  28. 28. proj/ Makefile.PL lib/ Cool.pm Makefile.PL Makefile.PL lib/ lib/ Cool.pm
  29. 29. proj/ Makefile.PL lib/ Cool.pm Makefile.PL Makefile.PL lib/ lib/ Cool.pm Cool.pm
  30. 30. proj/ Makefile.PL lib/ Cool.pm Makefile.PL Makefile.PL Makefile.PL lib/ lib/ lib/ Cool.pm Cool.pm
  31. 31. proj/ Makefile.PL lib/ Cool.pm Makefile.PL Makefile.PL Makefile.PL lib/ lib/ lib/ Cool.pm Cool.pm
  32. 32. proj/ Makefile.PL lib/ Cool.pm Makefile.PL Makefile.PL Makefile.PL lib/ lib/ lib/ Cool.pm Cool.pm
  33. 33. References • “Names” for commits • Mutable, they point to a specific commit and move to a new one after each commit Name • A branch is a reference, a name to a commit • Special HEAD reference: points to a reference
  34. 34. proj/ Makefile.PL lib/ Cool.pm Makefile.PL Makefile.PL Makefile.PL lib/ lib/ lib/ Cool.pm Cool.pm
  35. 35. master HEAD
  36. 36. master HEAD
  37. 37. master HEAD test
  38. 38. master test HEAD
  39. 39. master test HEAD
  40. 40. master HEAD test
  41. 41. test master HEAD
  42. 42. test master Merge
  43. 43. test Merge master
  44. 44. test master Rebase
  45. 45. master Rebase test
  46. 46. master Rebase test
  47. 47. Rebase + Merge master test
  48. 48. Rebase + Merge master test
  49. 49. Non-SCM uses for Git • Leverage strengths • immutable • over network pulls only missing objects • fast checkout (compare to copy, less to read) • easy rollback
  50. 50. Beware of weak points • Always stores full copy of files • not good for backups of DB dumps • Full history more disk space • this might chance as “shallow clones” gain funcionality...
  51. 51. Content distribution • Updates done in a master, central repository • Hierarchy of slave repositories • Fast sync between repositories, fast checkout • Can be automated with hooks • Useful if you have lots of static files, faster than rsync
  52. 52. Read-only filesystem • Design web server that fetch objects directly from the object database • Compact storage, efficient retrieval • Packs of objects also very VM friendly, mmap ready • Some solutions already available OSS
  53. 53. Wiki/Ticketing backend • Use git repository as storage for wiki or ticketing systems • Good match for distributed developement • Several solutions already available OSS • ... but similar to SCM usages
  54. 54. That’s all folks! • I’ll be around #codebits, feel free to ask me stuff • If you want a git as a SCM demo, lets get organized and I’ll do a impromptu presentation, or even private lapdan^H^H^H^H^Hdemos • After #codebits <{mailto,xmpp}:melo@simplicidade.org
  55. 55. About Git http://git-scm.com/ Git Internals: http://peepcode.com/products/git-internals-pdf Git book: http://progit.org/ About Me http://simplicidade.org/notes/ @pedromelo {mailto,xmpp}:melo@simplicidade.org skype:melopt http://github.com/melo http://www.slideshare.net/melopt
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×