$30 off During Our Annual Pro Sale. View Details »

内部構造から学ぶGit

A1
April 24, 2017

 内部構造から学ぶGit

社内勉強会資料

A1

April 24, 2017
Tweet

More Decks by A1

Other Decks in Programming

Transcript

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

  2. f5aecbff04f484dcf74e14f c6961da0a8b6d43ad

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

  4. commit ff86faf2fa02bc21933c9e1dcc75c8d81b3e104a Merge: 8f8d0ec 552a736 Author: Taro <taro@example.com> Date: Wed

    Aug 19 14:49:37 2015 -0700 Bugfix xxx commit 8f8d0ecfde871144ae839876039fe4e8fed75a9c Author: Taro <taro@example.com> Date: Wed Aug 19 14:46:09 2015 -0700 Refactoring xxx commit 011710a315a5e4157e882880fe77798f8d4adde0 Merge: 8c9155e 09bb652 Author: Taro <taro@example.com> Date: Wed Aug 19 14:48:56 2015 -0700 Merge branch 'todo' git logͷ݁Ռ
  5. Q. ԿͰsha1ϋογϡͳͷʁ svnΈ͍ͨʹγʔέϯεͷํ͕ྑ͘ͳ ͘ͳ͍ʁ

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

  7. ϦϏδϣϯ1ͬͯԿΑ தԝϦϙδτϦ "͞ΜͷϩʔΧϧ #͞ΜͷϩʔΧϧ      →෼ࢄ؀ڥશମͰϢχʔΫͰ͋Δඞཁ͕͋Δ

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  22. commitΦϒδΣΫτ $ git cat-file -p ff86fa tree c95970c3507b89fe43181df983f73c8f1db262fb parent 8f8d0ecfde871144ae839876039fe4e8fed75a9c

    parent 552a736de775994570570a0514f24e32686afbe0 author Taro <taro@exmple.com> 1440020977 -0700 committer Taro <taro@example.com> 1440020977 -0700 Bugfix: xxx
  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 ϑΝΠϧͱϑΥϧμͷ৘ใΛ อ͍࣋ͯ͠Δɻ
  24. blobΦϒδΣΫτ $ git cat-file -p 4223f1 package main import “fmt”

    fun main() { fmt.Printf(“Hello World”) } ಡΊΔʂಡΊΔͧʂʂ
  25. Q. GitͷΦϒδΣΫτ͸Ͳ͜ʹอଘ ͞Ε͍ͯΔͷʁ

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

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

  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 <eichisanden@example.com> 1440425753 +0900 committer eichisanden <eichisanden@example.com> 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 ϋογϡ͸ಉ͡஋ͳͷͰແବͳΦ ϒδΣΫτ͸࡞ΒΕͳ͍ʂ
  30. ϑΝΠϧ໊͕ҧ͓͏͕ɺ อଘϑΥϧμ͕ҧ͓͏͕ɺ ಺༰͕ಉ͡ͳΒಉ͡ϋογϡʹͳΔʂ

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

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

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

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

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

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