Save 37% off PRO during our Black Friday Sale! »

About Git at Cookpad Summer Intern 2016 day1

About Git at Cookpad Summer Intern 2016 day1

70e13d9877054026fda46d5a5b53a236?s=128

MOROHASHI Kyosuke

August 12, 2016
Tweet

Transcript

  1. Gitʹ͍ͭͯ 2016-08-12 ΫοΫύουαϚʔΠϯλʔϯ 2016 ٕज़෦ ։ൃج൫ @moro ॾڮګհ 

  2. ‣ Git is a free and open source distributed version

    control system designed to handle everything from small to very large projects with speed and efficiency. ‣ https://git-scm.com/ (JU 
  3.  https://services.github.com/resources/

  4. Git is a free and open source distributed 
 version

    control system 
  5. ‣ ෳ਺ϑΝΠϧΛมߋ͠ͳ͕Β࡞Διϑτ΢ΣΞʹ͓͍ͯɺ ͋Δ࣌఺ͷʮߏ੒ʯΛϦϏδϣϯͱͯ͠อ࣋Ͱ͖Δɻ ‣ ೚ҙͷϦϏδϣϯͷ಺༰Λ෮ݩͰ͖Δɻ ‣ ϦϏδϣϯͷཤྺΛอ࣋Ͱ͖Δɻ ‣ ͭલͷϦϏδϣϯʹ໭Δɺͱ͔΋Ͱ͖Δɻ version

    control system: what? 
  6. ‣ Git is a content-addressable filesystem. Great. ‣ see https://git-scm.com/book/en/v2/

    | Section 10.2 ‣ …Ͳ͏͍͏͜ͱͳͷ? (JUͷϦϏδϣϯ؅ཧ 
  7. ‣ ϑΝΠϧ΍σΟϨΫτϦͷத਎ΛɺϦϙδτϦͷϧʔτ͔ ΒḷΔ໦ߏ଄Ͱอ͍࣋ͯ͠Δɻ ‣ ϑΝΠϧγεςϜ্ͷσΟϨΫτϦɺϑΝΠϧͱಉ͡ ‣ σΟϨΫτϦʹ౰ͨΔͷ͕USFF ‣ ϑΝΠϧʹ౰ͨΔͷ͕CMPC (JUͷϦϏδϣϯ؅ཧ

    
  8.  Figure 10-1@ https://git-scm.com/book/en/v2/Git-Internals-Git-Objects

  9. ‣ ͋Δ࣌఺ͷϦϏδϣϯ ϝλσʔλ͕DPNNJU ‣ ͍ͭɺ୭͕ɺͲΜͳϝοηʔδͰίϛοτ͔ͨ͠ ‣ ϦϏδϣϯͷϧʔτUSFF͸ͲΕ͔ ‣ ਌DPNNJU͸ͲΕ͔ ‣

    DPNNJUͷੵΈॏͶιϑτ΢ΣΞͷཤྺ DPNNJU 
  10. ‣ (JUͷϦϏδϣϯ؅ཧ͸DPNNJU USFF CMPCͷछྨͷ HJUPCKFDUͰ࣮ݱ͞Ε͍ͯΔɻ ‣ ͦΕͧΕͷHJUPCKFDU͸TIBͰͷJEͰࢀরͰ͖Δ DPNNJU USFF CMPC

    
  11. $ git clone git@ghe.example.com:moro/fizz-buzz-git.git $ git log --oneline c827de7 Add

    note 99c0455 Init FizzBuzz $ git cat-file -p 99c0455 tree 4ddd72269bffbe854007323f6b753e47dd3498ae author moro <kyosuke-morohashi@cookpad.com> 1466746090 +0900 committer moro <kyosuke-morohashi@cookpad.com> 1466746090 +0900 Init FizzBuzz $ git cat-file -p 4ddd72269bffbe854007323f6b753e47dd3498ae 100644 blob fb738ec4422280fa0938c1cf2363f244168ffa5d fizz_buzz.rb $ git cat-file -p fb738ec4422280fa0938c1cf2363f244168ffa5d 1.upto(100).each do |n| if (n % 15).zero? puts 'FizuBazu' ... DPNNJUUSFF ϝλσʔλ 
  12.  99c0455 4ddd7226 fb738ec44 2016-06-24 14:28:10 Init FizzBuzz fizz_buzz.rb 1.upto(100).each

    do if (n % 15).zero? puts 'FizuBazu' commit tree blob
  13. $ git log --oneline c827de7 Add note 99c0455 Init FizzBuzz

    $ git cat-file -p c827de7 tree 0b6d5f879bab3bdb4856c67a908d430f0bb3f18d parent 99c045537a1deb673a70c72bebbd9a91490068b0 author moro <kyosuke-morohashi@cookpad.com> 1466746241 +0900 committer moro <kyosuke-morohashi@cookpad.com> 1466746241 +0900 Add note $ git cat-file -p 0b6d5f879bab3bdb4856c67a908d430f0bb3f18d 100644 blob 63d8ebbbad7040256bd8f4d12a51df27e75888ce README.md 100644 blob fb738ec4422280fa0938c1cf2363f244168ffa5d fizz_buzz.rb DPNNJUUSFF ϝλσʔλ 
  14.  99c0455 c827de7 4ddd7226 0b6d5f87 fb738ec44 fb738ec44 63d8ebbba 2016-06-24 14:30:41

    Add note 2016-06-24 14:28:10 Init FizzBuzz README.md fizz_buzz.rb fizz_buzz.rb 1.upto(100).each do if (n % 15).zero? puts 'FizuBazu' 1.upto(100).each do if (n % 15).zero? puts 'FizuBazu' FizzBuzz example to commit tree blob parent
  15.  99c0455 c827de7 4ddd7226 0b6d5f87 fb738ec44 63d8ebbba 2016-06-24 14:30:41 Add

    note 2016-06-24 14:28:10 Init FizzBuzz README.md fizz_buzz.rb fizz_buzz.rb 1.upto(100).each do if (n % 15).zero? puts 'FizuBazu' FizzBuzz example to commit tree blob parent
  16. ‣ Git is a content-addressable filesystem. Great. ‣ see https://git-scm.com/book/en/v2/

    | Section 10.2 ‣ ͳΔ΄Ͳ (JU*OUFSOBMT 
  17.  99c0455 c827de7 4ddd7226 0b6d5f87 fb738ec44 63d8ebbba 2016-06-24 14:30:41 Add

    note 2016-06-24 14:28:10 Init FizzBuzz README.md fizz_buzz.rb fizz_buzz.rb 1.upto(100).each do if (n % 15).zero? puts 'FizuBazu' FizzBuzz example to commit tree blob parent
  18. ‣ commit ΛੵΈॏͶΔࢬΛෳ਺؅ཧͰ͖Δ CSBODI 

  19.  A2 A1 A3 A4 B2 B1 B3 X

  20. ‣ ෳ਺ͷcommitΛ਌ʹ࣋ͭcommitΛ࡞੒͢Δ ‣ tree / blobͷத਎͸ɺ *ݡ͘* ߹ྲྀ͢Δ ‣ ࣗಈతʹ߹ྲྀ͖ͤ͞Εͳ͍ͱίϯϑϦΫτ

    NFSHF 
  21.  A2 A1 A3 A4 B2 B1 B3 X X(m)

  22. ‣ commitࠩ෼Λผͷى఺(base)্ʹ࠶(re)ద༻͢Δ ‣ ผϒϥϯνͰͭͬͨ͘ػೳΛͱΓࠐΜͩΓ ‣ commitࠩ෼Λฤूͨ͠Γ࡟আͨ͠Γ·ͱΊͨΓ SFCBTF 

  23. ϒϥϯνBͰͷ࡞ۀதɺA4Λbaseʹͨ͘͠ͳͬͨ  A2 A1 A3 A4 B2 B1 B3 X

    A/HEAD B/HEAD $ git checkout B working copy
  24. ϒϥϯνBͰͷ࡞ۀதɺA4Λbaseʹͨ͘͠ͳͬͨ  A2 A1 A3 A4 B2 B1 B3 X

    A/HEAD B/HEAD $ git rebase A working copy
  25.  A2 A1 A3 A4 B2 B1 B3 X A/HEAD

    B2' B1' B3' B/HEAD working copy ແ໊ϒϥϯν A4ͷ্ʹB1, B2, B3ͱಉ౳ͷมߋΛద༻͠ɺ ͦΕ͕ϒϥϯνBʹͳΔ $ git rebase A
  26.  A2 A1 A3 A4 X A/HEAD B2' B1' B3'

    B/HEAD A3,4 B1'' B3'' ແ໊ϒϥϯν ͜ͷ৔߹΋ɺ౷߹࡟আͨ͠ίϛοτΛ ى఺Xͷ্ʹੵΈॏͶͨ৽ͨͳίϛοτ͕Ͱ͖ɺ ϒϥϯνBͷHEAD͕ߋ৽͞ΕΔɻ B2 B1 B3 ͖ͬ͞ͷ ແ໊ϒϥϯν $ git rebase -i X
  27. ‣ SFCBTF͢Ε͹͍͍ͱ͍͏΋ͷͰ͸ͳ͍ ‣ DPNNJU͕ผ෺ʹͳΔɺࠩ෼ద༻ͰϋϚΔɺͳͲ ‣ Ұ౓ʹͭͣͭ SFCBTFJ͍ͯ͠Δ࠷தʹ৽ػೳΛೖΕͳ͍  ‣ ͖͞΄Ͳͷʮແ໊ϒϥϯνʯ΋ɺDPNNJU͕Θ͔Ε͹ϦϏδϣ

    ϯΛ෮ݩͰ͖ΔͷͰ҆৺ɻ ‣ HJUSFqPHͰݟΒΕΔ࡞ۀίϐʔͷཤྺ͔Β୳ͤΔɻ rebase: protip 
  28. Git is a free and open source distributed version control

    system 
  29. ‣ ଞͷ։ൃऀ͕ͭͬͨ͘ιϑτ΢ΣΞͷϦϏδϣϯͷཤྺΛɺ ωοτϫʔΫӽ͠ʹऔಘͰ͖Δɻ ‣ DMPOFҾ਺Ͱࢦఆͨ͠ϦϙδτϦΛऔಘ͢Δ ‣ औಘݩΛද͢ϦϞʔτPSJHJO͕௥Ճ͞ΕΔ DMPOF࠷ॳͷऔಘ 

  30. ‣ ։ൃ͍ͯͬͨ͠ιϑτ΢ΣΞͷϦϏδϣϯͷཤྺΛɺ
 ωοτϫʔΫӽ͠ʹଞͷ։ൃऀͱڞ༗Ͱ͖Δ ‣ QVTIखݩͷDPNNJU ਌DPNNJUΛؚΉ ΛϦϞʔτͷ
 ϦϙδτϦʹૹΔ ‣ ओϦϞʔτϦϙδτϦ͸PSJHJOͱ͍͏໊લ͕Ұൠత

    QVTIࣗ෼ͷDPNNJUΛૹ৴ 
  31. $ git push origin master QVTIͷྫ ‣ ϩʔΧϧͷϦϙδτϦͷNBTUFSϒϥϯνʹੵΈॏͶͨDPNNJUͷཤྺΛ ‣ PSJHJOͱ͍͏໊લͷϦϞʔτϦϙδτϦͷ

    ‣ NBTUFSϒϥϯνʹૹΔ 
  32. $ git push moro 12345678:topic-a QVTIͷྫ  ‣ ϩʔΧϧͷϦϙδτϦDPNNJU͔ΒḷΕΔཤྺΛ ‣

    NPSPͱ͍͏໊લͷϦϞʔτϦϙδτϦͷ ‣ UPQJDBϒϥϯνʹૹΔ 
  33. $ git remote show origin * remote origin Fetch URL:

    git@ghe.example.com:moro/clock.git Push URL: git@ghe.example.com:moro/clock.git HEAD branch: master Remote branch: master tracked Local ref configured for 'git push': master pushes to master (up to date) "remote" ͷϦϙδτϦ...? ‣ ʮͷ໊લͷϦϞʔτϦϙδτϦʯ 
  34. $ git fetch origin GFUDIDMPOFޙͷऔಘ ‣ ϦϞʔτϦϙδτϦͷDPNNJUΛɺϩʔΧϧʹ࣋ͬ ͯ͘Δ ‣ ࣋ͬͯ͘Δ͚ͩɺखݩͷίʔυ

    ࡞ۀίϐʔ ͸มΘ Βͳ͍ 
  35. $ git pull origin QVMMGFUDI NFSHF ‣ ϦϞʔτϦϙδτϦ͔ΒGFUDI͠ɺNFSHF͢Δ ‣ ࡞ۀίϐʔ͕มߋ͞ΕΔ

    ‣ ׳ΕΔ·Ͱ͸͓͢͢Ί͠ͳ͍ ‣ pull --rebase ͢ΔͱGFUDI SFCBTF ‣ ׳ΕΔ·Ͱ͸ϚδͰ͓͢͢Ί͠ͳ͍ 
  36. 

  37. GitHub fosters a fast, flexible, and collaborative development process that

    lets you work on your own or with others. 
  38. GitHub fosters a fast, flexible, and collaborative development process that

    lets you work on your own or with others. 
  39. ‣ ͭͷϦϙδτϦʹରͯ͠ ‣ ෳ਺ͷϓϩάϥϚ͕ ‣ ෳ਺ͷมߋΛߦ͏ (JU)VC()&Λ࢖ͬͨίϥϘϨʔγϣϯ 

  40. ‣ มߋ͍ͯ͠Δ࠷தʹɺଞऀͷมߋͱিಥ͠ͳ͍؀ڥ ‣ มߋ಺༰ΛɺνʔϜͰϨϏϡʔ͢Δ࢓૊Έ ‣ ։ൃϨϏϡʔ׬ྃͨ͠มߋΛɺத৺ͷϦϙδτϦʹ
 ద༻͢Δ࢓૊Έ ‣ த৺ϦϙδτϦʹೖͬͨଞऀͷมߋΛऔಘ͢Δ࢓૊Έ ίϥϘϨʔγϣϯʹඞཁͳ΋ͷ

    
  41.  cookpad/app working copy $ git fetch origin $ git

    checkout origin/master
 -b topic $ git add ... $ git commit -m '' $ git push -u origin topic commit commit clone fetch push FH(JU)VCqPXͱݺ͹Ε͍ͯΔ΋ͷ
  42.  cookpad/app - cookpad/app:topic working copy $ git fetch origin

    $ git checkout origin/master
 -b topic $ git add ... $ git commit -m '' $ git push -u origin topic commit commit clone fetch push
  43.  cookpad/app - cookpad/app:topic working copy $ git fetch origin

    $ git checkout origin/master
 -b topic $ git add ... $ git commit -m '' $ git push -u origin topic commit commit clone fetch push pull request
  44.  cookpad/app - cookpad/app:topic working copy $ git fetch origin

    $ git checkout origin/master
 -b topic $ git add ... $ git commit -m '' $ git push -u origin topic commit commit clone fetch push pull request ‣ มߋ͍ͯ͠Δ࠷தʹɺଞऀͷมߋͱিಥ͠ͳ͍؀ڥ ‣ มߋ಺༰ΛɺνʔϜͰϨϏϡʔ͢Δ࢓૊Έ ‣ ։ൃϨϏϡʔ׬ྃͨ͠มߋΛɺத৺ͷ
 ϦϙδτϦʹద༻͢Δ࢓૊Έ ‣ த৺ϦϙδτϦʹೖͬͨ
 ଞऀͷมߋΛऔಘ͢Δ࢓૊Έ
  45. ‣ (JU)VCͳͲʹ͓͍ͯɺαʔό্ͷϦϞʔτϦϙδτϦΛ
 ෳ੡͢Δ͜ͱɻ ‣ 044։ൃͰɺதԝϦϙδτϦʹίϛοτݖ͕ͳ͍৔߹ʹࣗ෼ͷมߋΛஔ͘
 ϦϞʔτϦϙδτϦΛ࡞Δɻ ‣ ΫοΫύουࣾ಺ͷαʔϏε։ൃͰ΋͜ͷϞσϧΛͱ͍ͬͯΔɻ ‣ ։ൃऀ͕ଟ͔ͬͨΓɺதԝϦϙδτϦ͸QVTIGېࢭͨ͠Γ͢ΔͨΊ

    GPSL 
  46.  cookpad/app working copy $ git fetch origin $ git

    remote add moro git@.... $ git checkout origin/master
 -b topic $ git add ... $ git commit -m '' $ git push moro topic commit commit clone fetch push pull request moro/app - moro/app:topic
  47. 1. git@ghe.example.com:moro/fizz-buzz-git.gitΛDMPOF͠ͳ͍͞ 2. p[[@CV[[SCΛ UZQP͸ͦͷ··Ͱ ΋ͬͱྑ͍ίʔυʹॻ͖׵͑ɺDPNNJU͠ͳ͍͞ 3. PSJHJOpYUZQPϒϥϯνΛϚʔδ͠ͳ͍͞ ‣ ίϯϑϦΫτ͢Δ͸ͣͳͷͰɺͦΕΛղফ͠ͳ͍͞

    4. ϒϥ΢βͰhttps://ghe.example.com/moro/fizz-buzz-gitΛ։͖ɺ
 ϑΥʔΫ͠ͳ͍͞ 5. ϑΥʔΫޙʹग़དྷͨࣗ෼ͷϦϙδτϦΛϦϞʔτͱͯ͠ొ࿥͠ͳ͍͞ɻ͜ͷͱ͖ɺ44)ͷ 63-Λ࢖͏͜ͱɻ 6. ͰϚʔδͨ͠಺༰ΛϑΥʔΫͨ͠ϦϙδτϦʹQVTI͠ͳ͍͞ ࣮श෼ 
  48. 1. <"EWBODFE>τϐοΫϒϥϯνΛ࡞੒ͨ͠͏͑ͰԿ͔ػೳΛ௥Ճ͠ɺ
 moro/fizz-buzz-git ʹ1VMM3FRVFTU͠ͳ͍͞ ࣮श෼ 

  49. ‣ 1SP(JUCPPL ‣ ެࣜαΠτʹͯɺॻ੶ͷ׬શ൛ ๜༁෇͖ ͕͋ΔɻҰಡ͢ΔͱΑ͍ɻ ‣ https://git-scm.com/book/ja/v2 ‣ ʲ຋༁ʳ(JUΛϘτϜΞοϓ͔Βཧղ͢Δ

    ‣ ࠓ೔΍ͬͨΑ͏ʹDPNNJUΦϒδΣΫτΛ௨ͯ͡(JUΛཧղ͢Δهࣄɻ
 ݸਓతʹ͸ͱͯ΋໾ʹཱͬͨ ‣ http://keijinsonyaban.blogspot.jp/2011/05/git.html ‣ લ৬ͷษڧձͰಉ͡Α͏ͳࢿྉΛ࡞ͬͯ·ͨ͠ɻ΍͸ΓDPNNJUͷղઆ͕ଟ͍ ‣ https://speakerdeck.com/moro/my-mental-model-about-git ͋ΘͤͯಡΈ͍ͨ