×
Copy
Open
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Slide 1
Slide 1 text
Gitʹ͍ͭͯ 2017-08-08 ΫοΫύουαϚʔΠϯλʔϯ 2017 @moro ॾڮګհ
Slide 2
Slide 2 text
ॾڮګհ(@moro) Kyosuke MOROHASHI
Slide 3
Slide 3 text
https://speakerdeck.com/moro/pragprog-and-me
Slide 4
Slide 4 text
Eisuke Oishi
Slide 5
Slide 5 text
‣ 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
Slide 6
Slide 6 text
❌ gitίϚϯυͷ͍ํ ⭕ Gitͷ෦ߏ = commitॏཁ ⭕ Git(ͱGH(E)) ΛͬͨίϥϘϨʔγϣϯ ͖ΐ͏͢͜ͱ
Slide 7
Slide 7 text
https://services.github.com/resources/
Slide 8
Slide 8 text
Git is a free and open source distributed version control system
Slide 9
Slide 9 text
version control system
Slide 10
Slide 10 text
‣ ෳϑΝΠϧΛมߋ͠ͳ͕Β࡞ΔιϑτΣΞʹ͓͍ͯɺ ͋Δ࣌ͷʮߏʯΛϦϏδϣϯͱͯ͠อ࣋Ͱ͖Δɻ ‣ ҙͷϦϏδϣϯͷ༰Λ෮ݩͰ͖Δɻ ‣ ϦϏδϣϯͷཤྺΛอ࣋Ͱ͖Δɻ ‣ 3ͭલͷϦϏδϣϯʹΔɺͱ͔Ͱ͖Δɻ version control system: what?
Slide 11
Slide 11 text
‣ Git is a content-addressable filesystem. Great. ‣ see https://git-scm.com/book/en/v2/ | Section 10.2 ‣ …Ͳ͏͍͏͜ͱͳͷ? “version control” on Git
Slide 12
Slide 12 text
Git ͷϦϏδϣϯཧ commit, tree, blob ͷ3͕ͭϙΠϯτ
Slide 13
Slide 13 text
‣ ϑΝΠϧσΟϨΫτϦͷதΛɺϦϙδτϦͷϧʔτ͔ ΒḷΔߏͰอ͍࣋ͯ͠Δɻ ‣ ϑΝΠϧγεςϜ্ͷσΟϨΫτϦɺϑΝΠϧͱಉ͡ ‣ σΟϨΫτϦʹͨΔͷ͕ tree ‣ ϑΝΠϧʹͨΔͷ͕ blob tree, blob
Slide 14
Slide 14 text
Figure 10-1@ https://git-scm.com/book/en/v2/Git-Internals-Git-Objects
Slide 15
Slide 15 text
‣ ͋Δ࣌ͷϦϏδϣϯ + ϝλσʔλ͕ commit ‣ ͍ͭɺ୭͕ɺͲΜͳϝοηʔδͰίϛοτ͔ͨ͠ ‣ ϦϏδϣϯͷϧʔτtreeͲΕ͔ ‣ commitͲΕ͔ ‣ commitͷੵΈॏͶ = ιϑτΣΞͷཤྺ commit
Slide 16
Slide 16 text
‣ GitͷϦϏδϣϯཧcommit, tree, blob ͷ3छྨͷgit objectͰ࣮ݱ͞Ε͍ͯΔɻ ‣ ͦΕͧΕͷgit objectsha-1ͰͷidͰࢀরͰ͖Δ commit, tree, blob
Slide 17
Slide 17 text
‣ ʮ҉߸ֶతϋογϡؔʯͱݺΕΔϋογϡؔɺ·ͨ ͦͷؔͰऔಘͰ͖Δͷུশɻ ‣ ಉ͡σʔλ͔Βಉ͕͡Ͱ͖Δɻ ‣ ಉҰͷGitΦϒδΣΫτ͔ΒಉҰͷɺࣅͯΔ͚Ͳͪΐͬ ͱνΨͷ͔Βҧ͏͕औΕΔɻ ‣ ΦϒδΣΫτࣝผࢠʹͳΔ(͍ͷͰઌ಄ܻ͕දࣔ͞ΕΔ)ɻ FYI: SHA-1
Slide 18
Slide 18 text
$ git clone
[email protected]
/fizz-buzz-git.git $ git log --oneline c827de7 Add note 99c0455 Init FizzBuzz $ git cat-file -p 99c0455 tree 4ddd72269bffbe854007323f6b753e47dd3498ae author moro 1466746090 +0900 committer moro 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' ... commit = tree + ϝλσʔλ
Slide 19
Slide 19 text
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
Slide 20
Slide 20 text
$ git log --oneline c827de7 Add note 99c0455 Init FizzBuzz $ git cat-file -p c827de7 tree 0b6d5f879bab3bdb4856c67a908d430f0bb3f18d parent 99c045537a1deb673a70c72bebbd9a91490068b0 author moro 1466746241 +0900 committer moro 1466746241 +0900 Add note $ git cat-file -p 0b6d5f879bab3bdb4856c67a908d430f0bb3f18d 100644 blob 63d8ebbbad7040256bd8f4d12a51df27e75888ce README.md 100644 blob fb738ec4422280fa0938c1cf2363f244168ffa5d fizz_buzz.rb commit = tree + ϝλσʔλ
Slide 21
Slide 21 text
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
Slide 22
Slide 22 text
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
Slide 23
Slide 23 text
‣ Git is a content-addressable filesystem. Great. ‣ see https://git-scm.com/book/en/v2/ | Section 10.2 ‣ ͳΔ΄Ͳ Git Internals
Slide 24
Slide 24 text
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
Slide 25
Slide 25 text
commit commit blob treeͷ ϦϯΫ
Slide 26
Slide 26 text
tree, blob, commitΘ͔ͬͨɻ ΄͔ʹ merge rebase ͱ͍͏ͷ Α͘ฉ͚͘Ͳ?
Slide 27
Slide 27 text
‣ commit ΛੵΈॏͶΔࢬΛෳཧͰ͖Δ branch
Slide 28
Slide 28 text
A2 A1 A3 A4 B2 B1 B3 X
Slide 29
Slide 29 text
‣ ෳͷcommitΛʹ࣋ͭcommitΛ࡞͢Δ ‣ tree / blobͷதɺ *ݡ͘* ߹ྲྀ͢Δ ‣ ࣗಈతʹ߹ྲྀ͖ͤ͞Εͳ͍ͱίϯϑϦΫτ merge ?
Slide 30
Slide 30 text
A2 A1 A3 A4 B2 B1 B3 X X(m)
Slide 31
Slide 31 text
‣ commitࠩΛผͷى(base)্ʹ࠶(re)ద༻͢Δ ‣ ผϒϥϯνͰͭͬͨ͘ػೳΛͱΓࠐΜͩΓ ‣ commitࠩΛฤूͨ͠Γআͨ͠Γ·ͱΊͨΓ SFCBTF
Slide 32
Slide 32 text
ϒϥϯνBͰͷ࡞ۀதɺA4Λbaseʹͨ͘͠ͳͬͨ A2 A1 A3 A4 B2 B1 B3 X A/HEAD B/HEAD $ git checkout B $ git rebase A working copy
Slide 33
Slide 33 text
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
Slide 34
Slide 34 text
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
Slide 35
Slide 35 text
‣ rebase ͢Ε͍͍ͱ͍͏ͷͰͳ͍ ‣ commit ͕ผʹͳΔɺࠩద༻ͰϋϚΔɺͳͲ ‣ Ұʹ1ͭͣͭ (rebase -i͍ͯ͠Δ࠷தʹ৽ػೳΛೖΕͳ͍) ‣ ͖͞΄Ͳͷʮແ໊ϒϥϯνʯɺcommit ͕Θ͔ΕϦϏδϣ ϯΛ෮ݩͰ͖ΔͷͰ҆৺ɻ ‣ $ git reflog ͰݟΒΕΔ࡞ۀίϐʔͷཤྺ͔Β୳ͤΔɻ rebase: protip
Slide 36
Slide 36 text
GitΛͬͨ ίϥϘϨʔγϣϯ
Slide 37
Slide 37 text
Git is a free and open source distributed version control system
Slide 38
Slide 38 text
‣ ଞͷ։ൃऀ͕ͭͬͨ͘ιϑτΣΞͷϦϏδϣϯͷཤྺΛɺ ωοτϫʔΫӽ͠ʹऔಘͰ͖Δɻ ‣ clone: ҾͰࢦఆͨ͠ϦϙδτϦΛऔಘ͢Δ ‣ औಘݩΛද͢ϦϞʔτ origin ͕Ճ͞ΕΔ clone : ࠷ॳͷऔಘ
Slide 39
Slide 39 text
‣ ։ൃ͍ͯͬͨ͠ιϑτΣΞͷϦϏδϣϯͷཤྺΛɺ ωοτϫʔΫӽ͠ʹଞͷ։ൃऀͱڞ༗Ͱ͖Δ ‣ push: खݩͷ commit(commitΛؚΉ)ΛϦϞʔτͷ ϦϙδτϦʹૹΔ ‣ ओϦϞʔτϦϙδτϦ origin ͱ͍͏໊લ͕Ұൠత push : ࣗͷ commit Λૹ৴
Slide 40
Slide 40 text
$ git push origin master push ͷྫ ‣ ϩʔΧϧͷϦϙδτϦͷNBTUFSϒϥϯνʹੵΈॏͶͨDPNNJUͷཤྺΛ ‣ PSJHJOͱ͍͏໊લͷϦϞʔτϦϙδτϦͷ ‣ NBTUFSϒϥϯνʹૹΔ
Slide 41
Slide 41 text
$ git push moro 12345678:topic-a push ͷྫ(2) ‣ ϩʔΧϧͷϦϙδτϦDPNNJU͔ΒḷΕΔཤྺΛ ‣ NPSPͱ͍͏໊લͷϦϞʔτϦϙδτϦͷ ‣ UPQJDBϒϥϯνʹૹΔ
Slide 42
Slide 42 text
$ git remote show origin * remote origin Fetch URL:
[email protected]
:moro/clock.git Push URL:
[email protected]
:moro/clock.git HEAD branch: master Remote branch: master tracked Local ref configured for 'git push': master pushes to master (up to date) "remote" ͷϦϙδτϦ...? ‣ ʮͷ໊લͷϦϞʔτϦϙδτϦʯ
Slide 43
Slide 43 text
$ git fetch origin fetch: clone ͨ͠ޙʹՃ͞Εͨcommitͷऔಘ ‣ ϦϞʔτϦϙδτϦͷDPNNJUΛɺϩʔΧϧʹ࣋ͬ ͯ͘Δ ‣ ࣋ͬͯ͘Δ͚ͩɺखݩͷίʔυ ࡞ۀίϐʔ มΘ Βͳ͍
Slide 44
Slide 44 text
L2 L1 L3 L4 R2 R1 R3 X working copy ผͷਓ͕࡞ͬͨ ίϛοτ
Slide 45
Slide 45 text
L2 L1 L3 L4 R2 R1 R3 X working copy ผͷਓ͕࡞ͬͨ ίϛοτ fetch: working copyมΘΒͳ͍
Slide 46
Slide 46 text
$ git pull origin pull: fetch+merge ‣ ϦϞʔτϦϙδτϦ͔ΒGFUDI͠ɺNFSHF͢Δ ‣ ࡞ۀίϐʔ͕มߋ͞ΕΔ ‣ ׳ΕΔ·Ͱ͓͢͢Ί͠ͳ͍ ‣ pull --rebase ͢ΔͱGFUDISFCBTF ‣ ׳ΕΔ·ͰϚδͰ͓͢͢Ί͠ͳ͍
Slide 47
Slide 47 text
L2 L1 L3 L4 R2 R1 R3 X working copy ผͷਓ͕࡞ͬͨ ίϛοτ pull: working ͱ remote ͕Ϛʔδ͞ΕΔ L5
Slide 48
Slide 48 text
L2' L1' L3' L4' R2 R1 R3 X working copy ผͷਓ͕࡞ͬͨ ίϛοτ pull —rebase : rebase͞ΕΔ = Ln͕ผίϛοτʹͳΔ
Slide 49
Slide 49 text
GitHub(Enterprise)Ͱͷ ίϥϘϨʔγϣϯ
Slide 50
Slide 50 text
Slide 51
Slide 51 text
‣ 1ͭͷϦϙδτϦʹରͯ͠ ‣ ෳͷϓϩάϥϚ͕ ‣ ෳͷมߋΛߦ͏ GitHub/GHEΛͬͨίϥϘϨʔγϣϯ
Slide 52
Slide 52 text
‣ มߋ͍ͯ͠Δ࠷தʹɺଞऀͷมߋͱিಥ͠ͳ͍ڥ ‣ มߋ༰ΛɺνʔϜͰϨϏϡʔ͢ΔΈ ‣ ։ൃ&ϨϏϡʔྃͨ͠มߋΛɺத৺ͷϦϙδτϦʹ ద༻͢ΔΈ ‣ த৺ϦϙδτϦʹೖͬͨଞऀͷมߋΛऔಘ͢ΔΈ ίϥϘϨʔγϣϯʹඞཁͳͷ
Slide 53
Slide 53 text
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ͱݺΕ͍ͯΔͷ
Slide 54
Slide 54 text
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
Slide 55
Slide 55 text
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
Slide 56
Slide 56 text
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 ‣ มߋ͍ͯ͠Δ࠷தʹɺଞऀͷมߋͱিಥ͠ͳ͍ڥ ‣ มߋ༰ΛɺνʔϜͰϨϏϡʔ͢ΔΈ ‣ ։ൃϨϏϡʔྃͨ͠มߋΛɺத৺ͷ ϦϙδτϦʹద༻͢ΔΈ ‣ த৺ϦϙδτϦʹೖͬͨ ଞऀͷมߋΛऔಘ͢ΔΈ
Slide 57
Slide 57 text
‣ GitHubͳͲʹ͓͍ͯɺαʔό্ͷϦϞʔτϦϙδτϦΛ ෳ͢Δ͜ͱɻ ‣ OSS։ൃͰɺதԝϦϙδτϦʹίϛοτݖ͕ͳ͍߹ʹࣗͷมߋΛஔ͘ ϦϞʔτϦϙδτϦΛ࡞Δɻ ‣ ΫοΫύουࣾͷαʔϏε։ൃͰ͜ͷϞσϧΛͱ͍ͬͯΔɻ ‣ ։ൃऀ͕ଟ͔ͬͨΓɺதԝϦϙδτϦpush -fېࢭͨ͠Γ͢ΔͨΊ GPSL
Slide 58
Slide 58 text
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
Slide 59
Slide 59 text
❌ gitίϚϯυͷ͍ํ ⭕ Gitͷ෦ߏ = commitॏཁ ⭕ Git(ͱGH(E)) ΛͬͨίϥϘϨʔγϣϯ ͖ΐ͏ͨ͜͠ͱ
Slide 60
Slide 60 text
‣ 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 ͋ΘͤͯಡΈ͍ͨ
Slide 61
Slide 61 text
‣ Git ͿΜͷԋशTDDͱ߹ΘͤͯΓ·͢ɻ ‣ ͜͜·ͰͰ࣭͋Εʙ ࣭ٙλΠϜ