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

内部構造から学ぶGit

A1
April 24, 2017

 内部構造から学ぶGit

社内勉強会資料

A1

April 24, 2017
Tweet

More Decks by A1

Other Decks in Programming

Transcript

  1. ಺෦ߏ଄͔ΒֶͿGit
    @eichisanden

    View full-size slide

  2. f5aecbff04f484dcf74e14f
    c6961da0a8b6d43ad

    View full-size slide

  3. Gitͱ͍͑͹ɺSha1ϋογϡ40ܻ

    View full-size slide

  4. commit ff86faf2fa02bc21933c9e1dcc75c8d81b3e104a
    Merge: 8f8d0ec 552a736
    Author: Taro
    Date: Wed Aug 19 14:49:37 2015 -0700
    Bugfix xxx
    commit 8f8d0ecfde871144ae839876039fe4e8fed75a9c
    Author: Taro
    Date: Wed Aug 19 14:46:09 2015 -0700
    Refactoring xxx
    commit 011710a315a5e4157e882880fe77798f8d4adde0
    Merge: 8c9155e 09bb652
    Author: Taro
    Date: Wed Aug 19 14:48:56 2015 -0700
    Merge branch 'todo'
    git logͷ݁Ռ

    View full-size slide

  5. Q. ԿͰsha1ϋογϡͳͷʁ
    svnΈ͍ͨʹγʔέϯεͷํ͕ྑ͘ͳ
    ͘ͳ͍ʁ

    View full-size slide

  6. A. Git͸DVCSʢ෼ࢄܕόʔ
    δϣϯ؅ཧγεςϜʣ͔ͩΒ

    View full-size slide

  7. ϦϏδϣϯ1ͬͯԿΑ
    தԝϦϙδτϦ
    "͞ΜͷϩʔΧϧ
    #͞ΜͷϩʔΧϧ





    →෼ࢄ؀ڥશମͰϢχʔΫͰ͋Δඞཁ͕͋Δ

    View full-size slide

  8. ෼ࢄܕ͡Όͳ͔ͬͨͱͯ͠΋ɺ
    Git͸ίϛοτͷྺ࢙ͷվมʹ׮༰
    ͳͷͰɺγʔέϯεNo.͸߹Θͳ͍

    View full-size slide

  9. Q. ຖ౓40ܻ΋ࢦఆ͠ͳ͍ͱμϝͳ
    ͷʁ

    View full-size slide

  10. A. ඃΒͳ͚Ε͹ɺઌ಄4ܻͰOK
    େ͖ΊͷϦϙδτϦͰ΋6ܻࢦఆͰ͍͚Δ

    View full-size slide

  11. Q. ϋογϡ஋͸Ͳ͏΍ܾͬͯ·Δ
    ͷʁ

    View full-size slide

  12. A. ίϛοτͷ಺༰Ͱܾ·Δ

    View full-size slide

  13. Q. ϋογϡ஋͕ඃΔ͡Όͳ͍ʁ

    View full-size slide

  14. A. ඃΔʢՄೳੑ͸͋Δʣ

    View full-size slide

  15. Ͱ΋িಥͷՄೳੑ͸Ұஹೋઍԯͷͦ
    ͷ·ͨҰஹഒ

    View full-size slide

  16. ஍ٿ্ͷཻ࠭ͷઍೋඦഒͷ֬཰
    ʙPro Git 6ষΑΓʙ

    View full-size slide

  17. ී௨ʹ࢖͏෼ʹ͸ؾʹ͢Δඞཁͳ͍

    View full-size slide

  18. gitͷΦϒδΣΫτͷछྨ
    commit
    tree
    blob
    tagʢࠓճ͸࿩͠·ͤΜʣ

    View full-size slide

  19. Πϝʔδਤ
    HJUMPHͰΈͯͨͷ͸
    ͜͜ͷҰཡ

    View full-size slide

  20. Πϝʔδਤ
    ଞͷΦϒδΣΫτ΋Ұҙͳϋο
    γϡΛ͍࣋ͬͯΔ

    View full-size slide

  21. git cat-file ίϚϯυͰΦϒδΣΫ
    τͷதΛ೷͍ͯΈΑ͏

    View full-size slide

  22. commitΦϒδΣΫτ
    $ git cat-file -p ff86fa
    tree c95970c3507b89fe43181df983f73c8f1db262fb
    parent 8f8d0ecfde871144ae839876039fe4e8fed75a9c
    parent 552a736de775994570570a0514f24e32686afbe0
    author Taro 1440020977 -0700
    committer Taro 1440020977 -0700
    Bugfix: xxx

    View full-size slide

  23. treeΦϒδΣΫτ
    $ git cat-file -p c95970
    100644 blob 5e98806c6cc246acef5f539ae191710a0c06ad3f .gitattributes
    100644 blob a685ec1fb0ca49607431a65f1ccf035bb9b95a3a .gitignore
    100644 blob ece2951a2b1e1cdd611c7dc371e50501d416d1f8 .mailmap
    100644 blob 536e55524db72bd2acf175208aef4f3dfc148d42 COPYING
    040000 tree dbb0cc4bf1e93167118aa39e57c8b7efa9113598 Documentation
    100755 blob fc45283501a3b004edabc55781b486b37509dd37 GIT-VERSION-GEN
    ϑΝΠϧͱϑΥϧμͷ৘ใΛ
    อ͍࣋ͯ͠Δɻ

    View full-size slide

  24. blobΦϒδΣΫτ
    $ git cat-file -p 4223f1
    package main
    import “fmt”
    fun main() {
    fmt.Printf(“Hello World”)
    }
    ಡΊΔʂಡΊΔͧʂʂ

    View full-size slide

  25. Q. GitͷΦϒδΣΫτ͸Ͳ͜ʹอଘ
    ͞Ε͍ͯΔͷʁ

    View full-size slide

  26. A. .gitϑΥϧμͷத

    View full-size slide

  27. GitͷϑΥϧμߏ੒
    .git
    !"" HEAD ←HEAD͕Ͳ͜Λࢦ͍ࣔͯ͠͠Δ
    !"" config ←จࣈ௨ΓઃఆϑΝΠϧ
    !"" description
    !"" hooks ←hookεΫϦϓτ
    !"" info
    # %"" exclude
    !"" objects ←͜͜ʹΦϒδΣΫτ͕ೖ͍ͬͯΔ
    # !"" 22
    # # %"" 62de0c121f22df8e78f5a37d6e114fd322c0b0
    # !"" 3e
    # # %"" 2799e0729c58acb86bb40f19c8cb4b2b4f8e96
    # !"" 46
    # # %"" d2987acc571a47f9e69b585eb833f6e903b2cc
    # !"" 6c
    # # %"" c84aae39643fdb94d1699b74b07e2c6500cbaf
    # !"" info
    # %"" pack
    %"" refs
    !"" heads
    %"" tags
    8 directories, 13 files

    View full-size slide

  28. Q. શ͘ಉ͡಺༰ͷϑΝΠϧ͕͋ͬͨ
    ΒΦϒδΣΫτ͸ͲͷΑ͏ʹ֨ೲ͞
    ΕΔͷʁ

    View full-size slide

  29. ಉ͡಺༰ͷϑΝΠϧΛ࡞੒ͯ͠ΈΔ
    $ echo "hoge" > a.txt
    $ echo "hoge" > b.txt
    $ git add .
    $ git commit -m 'add a.txt and b.txt'
    [master (root-commit) 6cc84aa] add a.txt and b.txt
    2 files changed, 2 insertions(+)
    create mode 100644 a.txt
    create mode 100644 b.txt
    $ git cat-file -p 6cc84aa
    tree f5aecbff04f484dcf74e14fc6961da0a8b6d43ad
    author eichisanden 1440425753 +0900
    committer eichisanden 1440425753 +0900
    add a.txt and b.txt
    $ git cat-file -p f5aecbff
    100644 blob 2262de0c121f22df8e78f5a37d6e114fd322c0b0 a.txt
    100644 blob 2262de0c121f22df8e78f5a37d6e114fd322c0b0 b.txt
    $ git cat-file -p 2262
    hoge
    ϋογϡ͸ಉ͡஋ͳͷͰແବͳΦ
    ϒδΣΫτ͸࡞ΒΕͳ͍ʂ

    View full-size slide

  30. ϑΝΠϧ໊͕ҧ͓͏͕ɺ
    อଘϑΥϧμ͕ҧ͓͏͕ɺ
    ಺༰͕ಉ͡ͳΒಉ͡ϋογϡʹͳΔʂ

    View full-size slide

  31. ϋογϡ஋͕িಥͨ͠ͱ͖΋Git͸
    ಉ͡ಈ͖Λ͢Δ͸ͣ
    ʢલड़ͷ௨Γɺى͜Γಘͳ͍Ͱ͕͢ʣ

    View full-size slide

  32. Q. ϑΝΠϧΛࠩ෼Ͱ؅ཧ͠ͳ͍ͱɺ
    ͑Β͍༰ྔΛ৯͏ͷͰ͸ʁ

    View full-size slide

  33. ͔֬ʹcommit(git add)ͨ͠
    ௚ޙ͸༰ྔΛ৯͏

    View full-size slide

  34. ͨͩɺGCͰpackfileʹҠಈ͞Ε༰ྔ͸ݮΔͷͰେৎ෉
    .git
    !"" HEAD ←HEAD͕Ͳ͜Λࢦ͍ࣔͯ͠͠Δ
    !"" config ←จࣈ௨ΓઃఆϑΝΠϧ
    !"" description
    !"" hooks ←hookεΫϦϓτ
    !"" info
    # %"" exclude
    !"" objects
    # !"" 22
    # # %"" 62de0c121f22df8e78f5a37d6e114fd322c0b0
    # !"" 3e
    # # %"" 2799e0729c58acb86bb40f19c8cb4b2b4f8e96
    # !"" 46
    # # %"" d2987acc571a47f9e69b585eb833f6e903b2cc
    # !"" 6c
    # # %"" c84aae39643fdb94d1699b74b07e2c6500cbaf
    # !"" info
    # %"" pack ←͜͜ʹҠಈ͞ΕΔ
    %"" refs
    !"" heads
    %"" tags
    8 directories, 13 files

    View full-size slide

  35. ໌ࣔతʹgit gcίϚϯυΛଧͨͳͯ͘΋ɺ
    git pushͱ͔ͷλΠϛϯάͰউखʹ΍ͬ
    ͯ͘ΕΔͷͰɺීஈ͸ҙࣝ͠ͳͯ͘OK

    View full-size slide

  36. ಺෦ߏ଄Λ஌ΔͱgitΛ࢖͏ͷ
    ָ͕͘͠ͳΔ͔΋

    View full-size slide

  37. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide