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

gitの裏側をさぐる

Marina Nakagawa
April 19, 2018
450

 gitの裏側をさぐる

新人研修で喋った内容です

Marina Nakagawa

April 19, 2018
Tweet

More Decks by Marina Nakagawa

Transcript

  1. 7 ͨΊͯ͠ΈΑ͏ $git init Initialized empty Git repository in /Users/nakagawa/Projects/test-git/.git/

    GitΛ࢖͑ΔΑ͏ʹ͢Δ $ls -A ϑΥϧμͷத਎ΛݟΔ .gitϑΝΠϧ͕Ͱ͖͍ͯ·͢
  2. 8 ͨΊͯ͠ΈΑ͏ $ls .git HEAD config hooks objects branches description

    info refs .gitϑΝΠϧͷத਎ΛݟͯΈ·͠ΐ͏
  3. 9 ৽͘͠ϑΝΠϧΛ࡞ͬͯaddͯ͠ΈΑ͏ $echo 'hello' > README READMEϑΝΠϧΛͭ͘Γ·͢ $git add README

    READMEϑΝΠϧΛadd͠·͢ Index͕௥Ճ͞Εͨʂ $ls -A .git
 HEAD config hooks info refs branches description index objects .gitͷϑΝΠϧͷத਎ΛݟͯΈΔ
  4. 11 .git/indexͬͯͳΜͩΖ͏ʁ $git ls-files -s ΠϯσοΫεͷΦϒδΣΫτ໊ɺmode bitsɺstage number Λදࣔͤ͞ΔίϚϯυΛ࢖͏ ϑΝΠϧܕ

    SHA-1ϋογϡ஋ εςʔδ਺ ϑΝΠϧ໊ 100644 ce013625030ba8dba906f756967f9e9ca394464a 0 README ϑΝΠϧܕͷ100644͸README͕௨ৗͷϑΝΠϧͰ͋Δ͜ͱΛࣔ͢ εςʔδ਺͸Ϛʔδ͢Δͱ͖ͷڝ߹ͷঢ়ଶ
 (ڝ߹͕͋Δͱ̍Ҏ্ͷεςʔδ਺ 0ͩͱڝ߹ͳ͠) SHA-1ϋογϡ஋͸ϑΝΠϧ಺༰ʹج͍ͮͯܭࢉ͞ΕΔ160Ϗοτʹू໿͞ΕΔϥϯμϜͳ஋ ಺༰͕ҰจࣈͰ΋ҧ͏ͱผͷ஋ʹͳΔ catͰΈͯ΋Α͘Θ͔Βͳ͍ͷͰ
  5. 12 ΄Μͱʹҧ͏஋ʹͳΔͷʁ $echo 'hello!' > README $git add README $git

    ls-files -s READMEʹॻ͍ͨHelloΛHelle!ͱʂΛ଍ͯ͠ΈΑ͏ ϑΝΠϧܕ SHA-1ϋογϡ஋ εςʔδ਺ ϑΝΠϧ໊ 100644 4effa19f4f75f846c3229b9dbdbad14eff362f32 0 README ͔ͨ͠ʹ಺༰͕ҰจࣈͰ΋ҧ͏ͱผͷ஋ʹͳΔ
  6. 15 Ͳ͏΍ͬͯϋογϡ஋Λܭࢉ͢Δͷʁ ࠓճͷྫͩͱ (ΦϒδΣΫτܕ+σʔλαΠζ) Blob 7 (ϑΝΠϧ಺༰)σʔλ Hello! $echo 'hello!'

    | git hash-object --stdin
 gitͷػೳͰϋογϡ஋Λग़ͯ͠ΈΔ ಉ͡஋ͩʂ ͜ͷ৘ใΛ࢖ͬͯSHA-1ϋογϡ஋Λग़ͤΔ
  7. 20 ͜ͷϋογϡ஋ΛͲ͏࢖͍ͬͯΔͷʁ ѹॖͨ͠σʔλΛղಡͯ͠ΈΑ͏ $git cat-file -p 4effa
 -p :಺༰Λදࣔ ϋογϡ஋

    (ΦϒδΣΫτܕ+σʔλαΠζ) Blob 7 (ϑΝΠϧ಺༰)σʔλ Hello! ͪΌΜͱσʔλ͕͍Δ
  8. 22 ίϛοτ͢ΔͱͲ͏ͳΔͷʁ ίϛοτͯ͠ΈΑ͏ $git commit -m "1st commit" 
 .git/objectsͷத਎ΛݟͯΈ·͠ΐ͏


    (ݕࡧର৅ΛϑΝΠϧͷΈʹݶఆͯ͠ݕࡧ͢ΔΦϓγϣϯΛ෇͚ͨfindίϚϯυ) $find .git/objects -type f
 ←hello ←hello! ←ίϛοτͨ͠Β
 ૿͑ͯΔ?!
  9. 24 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(treeΦϒδΣΫτ) தΛղಡͯ͠ΈΑ͏ $git cat-file -t 34e600; git cat-file -s

    34e600; git cat-file -p 34e600;
 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 34(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧ໊ 100644 blob(ϑΝΠϧͷҙ) 4effa19f4f75f846c3229b9dbdbad14eff362f32 README treeΦϒδΣΫτ:34e600920700d3d2d96ff92e3c057a8d24b1f3ed
  10. 25 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(treeΦϒδΣΫτ) தΛղಡͯ͠ΈΑ͏ $git cat-file -t 34e600; git cat-file -s

    34e600; git cat-file -p 34e600;
 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 34(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧ໊ 100644 blob(ϑΝΠϧͷҙ) 4effa19f4f75f846c3229b9dbdbad14eff362f32 README ↑Hello!ɹʹมߋͨ͠ίϛοτͩ treeΦϒδΣΫτ:34e600920700d3d2d96ff92e3c057a8d24b1f3ed
  11. 26 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 34(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧ໊ 100644

    blob(ϑΝΠϧͷҙ) 4effa19f4f75f846c3229b9dbdbad14eff362f32 README ̋TreeΦϒδΣΫτ͸ίϛοτ࣌఺ͷΠϯσοΫε৘ใ͔Β࡞ΒΕΔ ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(treeΦϒδΣΫτ) ·ͱΊ (ΦϒδΣΫτܕ+σʔλαΠζ) Blob 7 (ϑΝΠϧ಺༰)σʔλ Hello! ̋TreeΦϒδΣΫτ͸࠷ޙʹaddͨ͠ϋογϡ஋ʹؔ࿈෇͚ΒΕ͍ͯΔ ͜ͷσʔλ͔Βϋογϡ஋͕࡞ΒΕ͍ͯΔ treeΦϒδΣΫτ:34e600920700d3d2d96ff92e3c057a8d24b1f3ed blobΦϒδΣΫτ:4effa19f4f75f846c3229b9dbdbad14eff362f32
  12. 27 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(commitΦϒδΣΫτ) தΛղಡͯ͠ΈΑ͏ $git cat-file -t 57c0a; git cat-file -s

    57c0a; git cat-file -p 57c0a; (ΦϒδΣΫτܕ+σʔλαΠζ) commit(ΦϒδΣΫτ) 195(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ TREE AUTHOR COMMITTER 34e600920700d3d2d96ff92e3c057a8d24b1f3ed Marina Nakagawa Marina Nakagawa commitΦϒδΣΫτ:57c0a4b5d3002202a7b55be6eb3523b992527d09
  13. 28 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(commitΦϒδΣΫτ) தΛղಡͯ͠ΈΑ͏ $git cat-file -t 57c0a; git cat-file -s

    57c0a; git cat-file -p 57c0a; (ΦϒδΣΫτܕ+σʔλαΠζ) commit(ΦϒδΣΫτ) 195(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ TREE AUTHOR COMMITTER 34e600920700d3d2d96ff92e3c057a8d24b1f3ed Marina Nakagawa Marina Nakagawa ↑TreeΦϒδΣΫτͰ͖ͨϋογϡ஋ͩ commitΦϒδΣΫτ:57c0a4b5d3002202a7b55be6eb3523b992527d09 CommitΦϒδΣΫτ͸͍ͭ୭͕ԿͷͨΊʹίϛοτͨ͠ͷ͔͕Θ͔Δ
  14. 29 ίϛοτΛ͢ΔͱTreeΦϒδΣΫτͱcommitΦϒδΣΫτ͕࡞੒͞ΕΔ ίϛοτ͢ΔͱͲ͏ͳΔͷʁ (ΦϒδΣΫτܕ+σʔλαΠζ) commit(ΦϒδΣΫτ) 195(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ TREE AUTHOR COMMITTER

    34e600920700d3d2d96ff92e3c057a8d24b1f3ed Marina Nakagawa Marina Nakagawa (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 34(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧ໊ 100644 blob(ϑΝΠϧͷҙ) 4effa19f4f75f846c3229b9dbdbad14eff362f32 README commitΦϒδΣΫτ:57c0a4b5d3002202a7b55be6eb3523b992527d09 treeΦϒδΣΫτ:34e600920700d3d2d96ff92e3c057a8d24b1f3ed (ΦϒδΣΫτܕ+σʔλαΠζ) Blob 7 (ϑΝΠϧ಺༰)σʔλ Hello! blobΦϒδΣΫτ:4effa19f4f75f846c3229b9dbdbad14eff362f32
  15. 31 ผϑΝΠϧΛͭͬͯ͘ίϛοτ͢ΔͱͲ͏ͳΔͷʁ $mkdir test $cd test $echo 'Hello world' >

    sample.md $git add sample.md $git commit -m "2nd commit” testϑΥϧμΛ࡞ͬͯ Hello worldͱॻ͔Εͨsample.mdϑΝΠϧΛͭ͘Δ
  16. 33 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(treeΦϒδΣΫτ) தΛղಡͯ͠ΈΑ͏ $git cat-file -t e3da65; git cat-file -s

    e3da64; git cat-file -p e3da64;
 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 65(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧɾϑΥϧμ໊ 100644 blob(ϑΝΠϧͷҙ) 4effa19f4f75f846c3229b9dbdbad14eff362f32 README 40000 tree(ϑΥϧμͷҙ) 3b903ecdee168aad30b478201b8ff9d9b20c6119 test treeΦϒδΣΫτ:e3da64ffcb70336e1313bad123247c9691846bac ←TreeΦϒδΣΫτ
  17. 34 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(treeΦϒδΣΫτ) தΛղಡͯ͠ΈΑ͏ $git cat-file -t e3da65; git cat-file -s

    e3da64; git cat-file -p e3da64;
 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 65(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧɾϑΥϧμ໊ 100644 blob(ϑΝΠϧͷҙ) 4effa19f4f75f846c3229b9dbdbad14eff362f32 README 40000 tree(ϑΥϧμͷҙ) 3b903ecdee168aad30b478201b8ff9d9b20c6119 test treeΦϒδΣΫτ:e3da64ffcb70336e1313bad123247c9691846bac ←TreeΦϒδΣΫτ ͜ͷTreeΦϒδΣΫτͰ͸̎ͭͷSHA-1ϋογϡ஋Λอ͍࣋ͯ͠Δ
  18. 35 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(treeΦϒδΣΫτ) தΛղಡͯ͠ΈΑ͏ $git cat-file -t e3da65; git cat-file -s

    e3da64; git cat-file -p e3da64;
 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 65(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧɾϑΥϧμ໊ 100644 blob(ϑΝΠϧͷҙ) 4effa19f4f75f846c3229b9dbdbad14eff362f32 README 40000 tree(ϑΥϧμͷҙ) 3b903ecdee168aad30b478201b8ff9d9b20c6119 test treeΦϒδΣΫτ:e3da64ffcb70336e1313bad123247c9691846bac ←TreeΦϒδΣΫτ ࣍͸͜ΕΛ͠Β΂ͯΈ·͢
  19. 36 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(treeΦϒδΣΫτ) (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 65(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧɾϑΥϧμ໊

    100644 blob(ϑΝΠϧͷҙ) 4effa19f4f75f846c3229b9dbdbad14eff362f32 README 40000 tree(ϑΥϧμͷҙ) 3b903ecdee168aad30b478201b8ff9d9b20c6119 test treeΦϒδΣΫτ:e3da64ffcb70336e1313bad123247c9691846bac தΛղಡͯ͠ΈΑ͏ $git cat-file -t 3b903; git cat-file -s 3b903; git cat-file -p 3b903;
 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 37(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧɾϑΥϧμ໊ 100644 blob(ϑΝΠϧͷҙ) 802992c4220de19a90767f3000a79a31b98d0df7 sample.md treeΦϒδΣΫτ:3b903ecdee168aad30b478201b8ff9d9b20c6119
  20. 37 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(treeΦϒδΣΫτ) (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 65(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧɾϑΥϧμ໊

    100644 blob(ϑΝΠϧͷҙ) 4effa19f4f75f846c3229b9dbdbad14eff362f32 README 40000 tree(ϑΥϧμͷҙ) 3b903ecdee168aad30b478201b8ff9d9b20c6119 test treeΦϒδΣΫτ:e3da64ffcb70336e1313bad123247c9691846bac தΛղಡͯ͠ΈΑ͏ $git cat-file -t 3b903; git cat-file -s 3b903; git cat-file -p 3b903;
 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 37(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧɾϑΥϧμ໊ 100644 blob(ϑΝΠϧͷҙ) 802992c4220de19a90767f3000a79a31b98d0df7 sample.md treeΦϒδΣΫτ:3b903ecdee168aad30b478201b8ff9d9b20c6119 ࣍͸͜ΕΛ͠Β΂ͯΈ·͢
  21. 38 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(blobΦϒδΣΫτ) தΛղಡͯ͠ΈΑ͏ $git cat-file -t 80299; git cat-file -s

    80299; git cat-file -p 80299;
 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 12(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ Hello world blobΦϒδΣΫτ:802992c4220de19a90767f3000a79a31b98d0df7 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 37(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧɾϑΥϧμ໊ 100644 blob(ϑΝΠϧͷҙ) 802992c4220de19a90767f3000a79a31b98d0df7 sample.md treeΦϒδΣΫτ:3b903ecdee168aad30b478201b8ff9d9b20c6119
  22. 39 ૿͑ͨϋογϡ஋ͷ಺ͷ̍ͭΛݟΔ(blobΦϒδΣΫτ) தΛղಡͯ͠ΈΑ͏ $git cat-file -t 80299; git cat-file -s

    80299; git cat-file -p 80299;
 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 12(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ Hello world blobΦϒδΣΫτ:802992c4220de19a90767f3000a79a31b98d0df7 (ΦϒδΣΫτܕ+σʔλαΠζ) treeΦϒδΣΫτ 37(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ ϑΝΠϧܕ ΦϒδΣΫτܕ SHA-1ϋογϡ஋ ϑΝΠϧɾϑΥϧμ໊ 100644 blob(ϑΝΠϧͷҙ) 802992c4220de19a90767f3000a79a31b98d0df7 sample.md treeΦϒδΣΫτ:3b903ecdee168aad30b478201b8ff9d9b20c6119 ಺༰Λมߋͨ͠σʔλ͕Ͱ͖ͯͨ
  23. 46 ೋͭ໨ͷίϛοτΦϒδΣΫτΛݟͯΈΑ͏ தΛղಡͯ͠ΈΑ͏ $git cat-file -t cff23; git cat-file -s

    cff23; git cat-file -p cff23; (ΦϒδΣΫτܕ+σʔλαΠζ) commit(ΦϒδΣΫτ) 243(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ TREE PARENT AUTHOR COMMITTER e3da64ffcb70336e1313bad123247c9691846bac 57c0a4b5d3002202a7b55be6eb3523b992527d09 Marina Nakagawa Marina Nakagawa commitΦϒδΣΫτ:cff23168b95204aa210c34f95394cafc00db847b
  24. 47 ೋͭ໨ͷίϛοτΦϒδΣΫτΛݟͯΈΑ͏ தΛղಡͯ͠ΈΑ͏ $git cat-file -t cff23; git cat-file -s

    cff23; git cat-file -p cff23; (ΦϒδΣΫτܕ+σʔλαΠζ) commit(ΦϒδΣΫτ) 243(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ TREE PARENT AUTHOR COMMITTER e3da64ffcb70336e1313bad123247c9691846bac 57c0a4b5d3002202a7b55be6eb3523b992527d09 Marina Nakagawa Marina Nakagawa commitΦϒδΣΫτ:cff23168b95204aa210c34f95394cafc00db847b ←͋ΕʁParent͕͍Δ
  25. 48 ೋͭ໨ͷίϛοτΦϒδΣΫτΛݟͯΈΑ͏ தΛղಡͯ͠ΈΑ͏ $git cat-file -t cff23; git cat-file -s

    cff23; git cat-file -p cff23; (ΦϒδΣΫτܕ+σʔλαΠζ) commit(ΦϒδΣΫτ) 243(σʔλαΠζ) (ϑΝΠϧ಺༰)σʔλ TREE PARENT AUTHOR COMMITTER e3da64ffcb70336e1313bad123247c9691846bac 57c0a4b5d3002202a7b55be6eb3523b992527d09 Marina Nakagawa Marina Nakagawa commitΦϒδΣΫτ:cff23168b95204aa210c34f95394cafc00db847b ←̍ͭલͷίϛοτΛࣔ͢