GitUnderstanding   January 6, 2010                     Jeff Kunkle
What’s Git?  Git is a free & open source, distributed version control system designed to handle everything from small to v...
Working Directory      ./           Rakefile           init.rb             lib              grant.rb
Working Directory       ./                          .git            Rakefile            init.rb              lib           ...
Working Directory       ./                          .git   What’s in here?            Rakefile            init.rb          ...
Objects
Git Objects header   object_type [content size]0          content of the file          can be textcontent   can be binary  ...
Git Objects     header   object_type [content size]0              content of the file              can be text    content  ...
1   Blobs
Working Directory        Git Directory      ./           Rakefile           init.rb             lib              grant.rb
Working Directory        Git Directory       ./            Rakefile            init.rb              lib               grant...
Working Directory        Git Directory       ./            Rakefile       blob : 21a307            init.rb       blob : 644...
Working Directory        Git Directory       ./            Rakefile       blob : 21a307            init.rb       blob : 644...
Blob Content
Blob Content  %w{ models }.each do |dir|    path = File.join(File.dirname(__FILE__), lib, app, dir)    $LOAD_PATH << path ...
2   Trees
Working Directory        Git Directory      ./           Rakefile        blob : 21a307           init.rb        blob : 644e...
Working Directory        Git Directory      ./                   tree : f2eb1e           Rakefile        blob : 21a307     ...
Tree Content
Tree Content  100644 blob 21a30738954b6bb164731d822efafa6c89c7bce7! Rakefile  100644 blob 644eda506db859e011ccbca5a06421ee...
Working Directory        Git Directory      ./                   tree : f2eb1e           Rakefile        blob : 21a307     ...
Working Directory        Git Directory      ./                   tree : f2eb1e           Rakefile        blob : 21a307     ...
3   Commits
Working Directory        Git Directory      ./                   tree : f2eb1e           Rakefile        blob : 21a307     ...
Working Directory        Git Directory      ./                   tree : f2eb1e           Rakefile        blob : 21a307     ...
Commit Content
Commit Content tree f2eb1e549e7e0d9cd5b7a580e63e9ce79d5a03ae author Jeff Kunkle <jkunkle@nearinfinity.com> 1261341813 -050...
Working Directory        Git Directory      ./                   tree : f2eb1e           Rakefile        blob : 21a307     ...
Working Directory        Git Directory      ./                   tree : f2eb1e           Rakefile        blob : 21a307     ...
Commit Contenttree ac451e549e7e0d9cd5b7a580e63e9ce79d5b45a1parent 3848fa7e91490a99b77590ff1385c4b3eebb3de3author Jeff Kunk...
4   Tags
./                  tree : f2eb1e     Rakefile        blob : 21a307     init.rb        blob : 644eda       lib          tre...
./                  tree : f2eb1e            Rakefile        blob : 21a307            init.rb        blob : 644eda         ...
Tag Content
Tag Content object 3848fa7e91490a99b77590ff1385c4b3eebb3de3 type commit tag v1.0 tagger Jeff Kunkle <jkunkle@ni.com> Tue D...
./                  tree : f2eb1e            Rakefile        blob : 21a307            init.rb        blob : 644eda         ...
./                  tree : f2eb1e            Rakefile        blob : 21a307            init.rb        blob : 644eda         ...
References
Basic Data Model        tag       commit        tree        blob
Basic Data Model        tag       commit                Immutable                Git Objects        tree        blob
Basic Data Model          tagbranch   commit                  Immutable                  Git Objects          tree        ...
Basic Data Model          tagbranch   commit                  Immutable                  Git Objects          tree        ...
Basic Data ModelHEAD      tagbranch   commit                  Immutable                  Git Objects          tree        ...
Basic Data Model  HEAD        tag  branch     commit                      Immutable                      Git Objects Mutab...
Working Directory      ./           Rakefile           init.rb             lib              grant.rb
HEADbranch   tagcommit tree    blob tree    blob blob
HEAD             HEAD  branch   tag     branch commit           commit   tree    blob     tree   tree    blob     tree   b...
HEAD             HEAD     HEAD  branch   tag     branch   branch commit           commit    commit   tree    blob     tree...
Branches
branch   branchcommit tree     C1 blob
masterC     C
master  C     C       idea>git checkout -b idea
master  C     C                C               idea>git commit
master  C     C                C               idea>git checkout master
master  C     C             C                C               idea>git commit
bug      master  C     C             C                C               idea>git checkout -b bug
bug      master                          C  C     C             C                C               idea>git commit
bug      master                          C  C     C             C                C               idea>git commit     check...
bug      master                          C  C     C             C                C               idea>git commitbug     me...
bug                            master                      C  C    C          C           C            C           idea>gi...
bug                            master                      C  C    C          C           C            C           idea>gi...
bug                            master                      C  C    C          C           C            C           idea>gi...
bug                           master                     C  C    C       C             C           C                      ...
bug                           master                     C  C    C       C             C           C                      ...
bug                          master                      C  C   C       C             C          C                        ...
bug                           master                       C  C    C       C             C           C                    ...
bug                                          master                       C  C    C       C           C                C  ...
bug                                          master                       C  C    C       C           C                C  ...
Recommendations
Starting new project?
Starting new project?           Use Git
Using SVN or CVS?
Using SVN or CVS?   Switch to Git
Using Team Studio?
Using Team Studio?   Maybe switch to Git
Using MKS?
Using MKS?   Switch to Git      or CVS, or Subversion, or anything else
ReferencesGood   Better                             Best                *most diagrams in this presentation are based on G...
Upcoming SlideShare
Loading in …5
×

Understanding Git Internals

3,980 views

Published on

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.

Published in: Technology
  • Be the first to comment

Understanding Git Internals

  1. 1. GitUnderstanding January 6, 2010 Jeff Kunkle
  2. 2. What’s Git? 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 completehistory and full revision tracking capabilities, not dependent on network access or a central server. Branching and merging are fast and easy to do.
  3. 3. Working Directory ./ Rakefile init.rb lib grant.rb
  4. 4. Working Directory ./ .git Rakefile init.rb lib grant.rb>git init
  5. 5. Working Directory ./ .git What’s in here? Rakefile init.rb lib grant.rb>git init
  6. 6. Objects
  7. 7. Git Objects header object_type [content size]0 content of the file can be textcontent can be binary can be whatever Zlib::Deflate
  8. 8. Git Objects header object_type [content size]0 content of the file can be text content can be binary can be whatever Zlib::Deflate1 Blob 2 Tree 3 Commit 4 Tag
  9. 9. 1 Blobs
  10. 10. Working Directory Git Directory ./ Rakefile init.rb lib grant.rb
  11. 11. Working Directory Git Directory ./ Rakefile init.rb lib grant.rb>git add .>git commit -m “initial commit”
  12. 12. Working Directory Git Directory ./ Rakefile blob : 21a307 init.rb blob : 644eda lib grant.rb blob : a22a24>git add .>git commit -m “initial commit”
  13. 13. Working Directory Git Directory ./ Rakefile blob : 21a307 init.rb blob : 644eda SHA-1 hashes lib of file content grant.rb blob : a22a24>git add .>git commit -m “initial commit”
  14. 14. Blob Content
  15. 15. Blob Content %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>git cat-file -p 644eda
  16. 16. 2 Trees
  17. 17. Working Directory Git Directory ./ Rakefile blob : 21a307 init.rb blob : 644eda lib grant.rb blob : a22a24
  18. 18. Working Directory Git Directory ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24
  19. 19. Tree Content
  20. 20. Tree Content 100644 blob 21a30738954b6bb164731d822efafa6c89c7bce7! Rakefile 100644 blob 644eda506db859e011ccbca5a06421ee76782ac7! init.rb 040000 tree 523fa41bd27fa29a00afb0bef6a10fde75aef501! lib>git cat-file -p f2eb1e
  21. 21. Working Directory Git Directory ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24
  22. 22. Working Directory Git Directory ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24
  23. 23. 3 Commits
  24. 24. Working Directory Git Directory ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24
  25. 25. Working Directory Git Directory ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24 commit : 3848fa
  26. 26. Commit Content
  27. 27. Commit Content tree f2eb1e549e7e0d9cd5b7a580e63e9ce79d5a03ae author Jeff Kunkle <jkunkle@nearinfinity.com> 1261341813 -0500 committer Jeff Kunkle <jkunkle@nearinfinity.com> 1261341813 -0500 initial commit first commit>git cat-file -p 3848fa
  28. 28. Working Directory Git Directory ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24 commit : 3848fa
  29. 29. Working Directory Git Directory ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24 commit : 3848fa
  30. 30. Commit Contenttree ac451e549e7e0d9cd5b7a580e63e9ce79d5b45a1parent 3848fa7e91490a99b77590ff1385c4b3eebb3de3author Jeff Kunkle <jkunkle@nearinfinity.com> 1261351813 -0500committer Jeff Kunkle <jkunkle@nearinfinity.com> 1261351813 -0500second commit next commit
  31. 31. 4 Tags
  32. 32. ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24 commit : 3848fa
  33. 33. ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24 commit : 3848fa tag : e9eff3>git tag -a v1.0
  34. 34. Tag Content
  35. 35. Tag Content object 3848fa7e91490a99b77590ff1385c4b3eebb3de3 type commit tag v1.0 tagger Jeff Kunkle <jkunkle@ni.com> Tue Dec 29 21:02:04 2009 -0500 version 1.0>git cat-file -p v1.0
  36. 36. ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24 commit : 3848fa tag : e9eff3>git tag -a v1.0
  37. 37. ./ tree : f2eb1e Rakefile blob : 21a307 init.rb blob : 644eda lib tree : 523fa4 grant.rb blob : a22a24 commit : 3848fa tag : e9eff3>git tag -a v1.0
  38. 38. References
  39. 39. Basic Data Model tag commit tree blob
  40. 40. Basic Data Model tag commit Immutable Git Objects tree blob
  41. 41. Basic Data Model tagbranch commit Immutable Git Objects tree blob
  42. 42. Basic Data Model tagbranch commit Immutable Git Objects tree blob
  43. 43. Basic Data ModelHEAD tagbranch commit Immutable Git Objects tree blob
  44. 44. Basic Data Model HEAD tag branch commit Immutable Git Objects Mutable treeReferences blob
  45. 45. Working Directory ./ Rakefile init.rb lib grant.rb
  46. 46. HEADbranch tagcommit tree blob tree blob blob
  47. 47. HEAD HEAD branch tag branch commit commit tree blob tree tree blob tree blob blob>git commit -a lib/grant.rb
  48. 48. HEAD HEAD HEAD branch tag branch branch commit commit commit tree blob tree tree blob tree blob tree blob blob blob>git commit -a Rakefile init.rb
  49. 49. Branches
  50. 50. branch branchcommit tree C1 blob
  51. 51. masterC C
  52. 52. master C C idea>git checkout -b idea
  53. 53. master C C C idea>git commit
  54. 54. master C C C idea>git checkout master
  55. 55. master C C C C idea>git commit
  56. 56. bug master C C C C idea>git checkout -b bug
  57. 57. bug master C C C C C idea>git commit
  58. 58. bug master C C C C C idea>git commit checkout master
  59. 59. bug master C C C C C idea>git commitbug merge
  60. 60. bug master C C C C C C idea>git commitbug merge
  61. 61. bug master C C C C C C idea>git commitbug bug branch merge -d
  62. 62. bug master C C C C C C idea>git commitbugidea checkout branch merge -d bug
  63. 63. bug master C C C C C C C idea>git commitbugidea checkout branch merge -d bug
  64. 64. bug master C C C C C C C C idea>git commitbugidea checkout branch merge -d bug
  65. 65. bug master C C C C C C C C idea>git commitbugidea checkout bug branch merge -dmaster
  66. 66. bug master C C C C C C C C idea>git commitbugidea checkout branch -dmaster merge ideabug
  67. 67. bug master C C C C C C C C C idea>git commitbugidea checkout branch -dmaster merge ideabug
  68. 68. bug master C C C C C C C C C idea>git commitbugidea checkout idea branch -dmaster merge ideabug
  69. 69. Recommendations
  70. 70. Starting new project?
  71. 71. Starting new project? Use Git
  72. 72. Using SVN or CVS?
  73. 73. Using SVN or CVS? Switch to Git
  74. 74. Using Team Studio?
  75. 75. Using Team Studio? Maybe switch to Git
  76. 76. Using MKS?
  77. 77. Using MKS? Switch to Git or CVS, or Subversion, or anything else
  78. 78. ReferencesGood Better Best *most diagrams in this presentation are based on Git internals

×