Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Understanding Git Internals

Understanding Git Internals

This is a quick introduction to the inner workings of Git, largely based on what I learned from reading Git Internals (https://peepcode.com/products/git-internals-pdf) and experimentation. It covers Git objects (blob, tree, commit, tag), references, and branches with incrementally building diagrams to help convey the concepts.

Jeff Kunkle

January 06, 2010
Tweet

More Decks by Jeff Kunkle

Other Decks in Programming

Transcript

  1. Git is a free & open source, distributed version control

    system designed to handle everything from small to very large projects with speed and efficiency. Every Git clone is a full-fledged repository with complete history and full revision tracking capabilities, not dependent on network access or a central server. Branching and merging are fast and easy to do. What’s Git?
  2. Git Objects header content object_type [content size]\0 content of the

    file can be text can be binary can be whatever Zlib::Deflate
  3. Git Objects 1 Blob 2 Tree 3 Commit 4 Tag

    header content object_type [content size]\0 content of the file can be text can be binary can be whatever Zlib::Deflate
  4. ./ Rakefile init.rb lib grant.rb Working Directory Git Directory blob

    : 21a307 >git add . >git commit -m “initial commit” blob : 644eda blob : a22a24
  5. ./ Rakefile init.rb lib grant.rb Working Directory Git Directory blob

    : 21a307 >git add . >git commit -m “initial commit” blob : 644eda blob : a22a24 SHA-1 hashes of file content
  6. Blob Content >git cat-file -p 644eda %w{ models }.each do

    |dir| path = File.join(File.dirname(__FILE__), 'lib', 'app', dir) $LOAD_PATH << path ActiveSupport::Dependencies.load_paths << path ActiveSupport::Dependencies.load_once_paths.delete(path) end
  7. ./ Rakefile init.rb lib grant.rb Working Directory Git Directory blob

    : 21a307 blob : 644eda blob : a22a24 tree : f2eb1e tree : 523fa4
  8. Tree Content >git cat-file -p f2eb1e 100644 blob 21a30738954b6bb164731d822efafa6c89c7bce7! Rakefile

    100644 blob 644eda506db859e011ccbca5a06421ee76782ac7! init.rb 040000 tree 523fa41bd27fa29a00afb0bef6a10fde75aef501! lib
  9. ./ Rakefile init.rb lib grant.rb Working Directory Git Directory blob

    : 21a307 blob : 644eda blob : a22a24 tree : f2eb1e tree : 523fa4
  10. ./ Rakefile init.rb lib grant.rb Working Directory Git Directory blob

    : 21a307 blob : 644eda blob : a22a24 tree : f2eb1e tree : 523fa4
  11. ./ Rakefile init.rb lib grant.rb Working Directory Git Directory blob

    : 21a307 blob : 644eda blob : a22a24 tree : f2eb1e tree : 523fa4
  12. ./ Rakefile init.rb lib grant.rb Working Directory Git Directory blob

    : 21a307 blob : 644eda blob : a22a24 tree : f2eb1e tree : 523fa4 commit : 3848fa
  13. Commit Content >git cat-file -p 3848fa tree f2eb1e549e7e0d9cd5b7a580e63e9ce79d5a03ae author Jeff

    Kunkle <[email protected]> 1261341813 -0500 committer Jeff Kunkle <[email protected]> 1261341813 -0500 initial commit first commit
  14. ./ Rakefile init.rb lib grant.rb Working Directory Git Directory blob

    : 21a307 blob : 644eda blob : a22a24 tree : f2eb1e tree : 523fa4 commit : 3848fa
  15. ./ Rakefile init.rb lib grant.rb Working Directory Git Directory blob

    : 21a307 blob : 644eda blob : a22a24 tree : f2eb1e tree : 523fa4 commit : 3848fa
  16. ./ Rakefile init.rb lib grant.rb blob : 21a307 blob :

    644eda blob : a22a24 tree : f2eb1e tree : 523fa4 commit : 3848fa
  17. ./ Rakefile init.rb lib grant.rb blob : 21a307 blob :

    644eda blob : a22a24 tree : f2eb1e tree : 523fa4 commit : 3848fa tag : e9eff3 >git tag -a v1.0
  18. Tag Content >git cat-file -p v1.0 object 3848fa7e91490a99b77590ff1385c4b3eebb3de3 type commit

    tag v1.0 tagger Jeff Kunkle <[email protected]> Tue Dec 29 21:02:04 2009 -0500 version 1.0
  19. ./ Rakefile init.rb lib grant.rb blob : 21a307 blob :

    644eda blob : a22a24 tree : f2eb1e tree : 523fa4 commit : 3848fa tag : e9eff3 >git tag -a v1.0
  20. ./ Rakefile init.rb lib grant.rb blob : 21a307 blob :

    644eda blob : a22a24 tree : f2eb1e tree : 523fa4 commit : 3848fa tag : e9eff3 >git tag -a v1.0
  21. blob tree commit tag branch HEAD blob tree blob tree

    commit branch HEAD tree blob >git commit -a lib/grant.rb
  22. >git commit -a Rakefile init.rb blob tree commit tag branch

    HEAD blob tree blob tree commit branch HEAD tree blob tree commit branch HEAD blob blob
  23. C C C idea C C C bug master >git

    commit >git merge bug >git commit
  24. C C C idea C C C bug master >git

    commit >git merge bug >git commit >git branch -d bug
  25. C C C idea C C C bug master >git

    commit >git merge bug >git commit >git branch -d bug >git checkout idea
  26. C C C C C idea C C bug master

    >git commit >git merge bug >git commit >git branch -d bug >git checkout idea >git commit
  27. C C C C C C C C idea bug

    master >git commit >git merge bug >git commit >git branch -d bug >git checkout idea >git commit >git commit
  28. C C C C C C C C idea bug

    master >git commit >git merge bug >git commit >git branch -d bug >git checkout idea >git commit >git commit >git checkout master
  29. C C C C C C C C idea bug

    master >git commit >git merge bug >git commit >git branch -d bug >git checkout idea >git commit >git commit >git checkout master >git merge idea
  30. C C C C C C C C C idea

    bug master >git commit >git merge bug >git commit >git branch -d bug >git checkout idea >git commit >git commit >git checkout master >git merge idea >git commit
  31. C C C C C C C C C idea

    bug master >git commit >git merge bug >git commit >git branch -d bug >git checkout idea >git commit >git commit >git checkout master >git merge idea >git commit >git branch -d idea