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

かたつむりにもわかる Git 超入門

かたつむりにもわかる Git 超入門

Keisuke SATO

June 01, 2014
Tweet

More Decks by Keisuke SATO

Other Decks in Technology

Transcript

  1. ͔ͨͭΉΓʹ΋Θ͔Δ Git ௒ೖ໳
    Keisuke SATO a.k.a. riaf

    View full-size slide

  2. @riaf
    ࠤ౻Ղ༞ (Keisuke SATO)
    1987/9/16
    !
    ๺ւಓ۴࿏ग़਎
    ۴࿏ބྕ → ๺ݟ޻ۀେֶ
    !
    Co-Founder and Engineer at
    Crocos Inc.
    !
    LOCAL
    Japan PHP Users Group
    Sapporo.php
    !
    Love Ohotech !

    View full-size slide

  3. Love Hokkaido,
    from Tokyo.

    View full-size slide

  4. ͔ͨͭΉΓ…ʁ

    View full-size slide

  5. ͳ͔ͥͨͭΉΓ޲͚ͷ࿩Λ͢Δ͜ͱʹͳ͔ͬͨ

    View full-size slide

  6. ๻ʹ༩͑ΒΕͨ;ͨͭͷબ୒ࢶ

    View full-size slide

  7. ͔ͨͭΉΓ…ʁ

    View full-size slide

  8. ͔ͨͭΉΓʹ΋Θ͔Δ Git ௒ೖ໳
    Keisuke SATO a.k.a. riaf

    View full-size slide

  9. ͦͷલʹ΋͏Ұݴ

    View full-size slide

  10. Thanks! Ohotech.
    ελοϑͷํʑɺ͓ർΕ͞·Ͱ͢ɻ
    ͋Γ͕ͱ͏͍͟͝·͢ɻ
    !
    ԕ͍Ͱ͕͢ɺԠԉ͓ͯ͠Γ·͢ʂ
    Կ͔͋ͬͨΒ͓ख఻͍͠·͢ͷͰ
    ͓ؾܰʹʂ

    View full-size slide

  11. ͔ͨͭΉΓʹ΋Θ͔Δ Git ௒ೖ໳
    Keisuke SATO a.k.a. riaf

    View full-size slide

  12. Git ͱ͸ ?
    • GitʢΪοτʣ͸ɺϓϩάϥϜͷιʔείʔυͳͲͷม
    ߋཤྺΛه࿥ɾ௥੻͢ΔͨΊͷ෼ࢄܕόʔδϣϯ؅ཧ
    γεςϜͰ͋Δɻ΋ͱ͸LinuxΧʔωϧͷιʔείʔυ
    ؅ཧʹ༻͍ΔͨΊʹϦʔφεɾτʔόϧζʹΑͬͯ։
    ൃ͞ΕɺͦΕҎ߱΄͔ͷଟ͘ͷϓϩδΣΫτͰ࠾༻͞
    Ε͍ͯΔɻLinuxΧʔωϧͷΑ͏ͳڊେϓϩδΣΫτʹ
    ΋ରԠͰ͖ΔΑ͏ʹɺಈ࡞଎౓ʹॏ఺͕ஔ͔Ε͍ͯΔɻ
    ݱࡏͷϝϯςφϯε͸ᖛ໺७ (Junio C Hamano) ͕୲౰
    ͍ͯ͠Δɻ
    Wikipedia contributors. "Git." Wikipedia. Wikipedia, 9 Mar. 2014. Web. 31 May. 2014.

    View full-size slide

  13. όʔδϣϯΛ؅ཧ͢Δ
    • ϑΝΠϧͷมߋʢ࡞੒ɾ࡟আʣΛه࿥͢Δ
    • ͍ͭɺͩΕ͕ɺͲͷΑ͏ʹʁ
    • ҎલͷόʔδϣϯͷϑΝΠϧΛऔΓग़ͤΔ
    • όοΫΞοϓతʹ࢖͑Δ

    View full-size slide

  14. ͳͥόʔδϣϯ؅ཧ͕ඞཁͳͷ͔

    View full-size slide

  15. ͳͥόʔδϣϯ؅ཧ͕ඞཁͳͷ͔
    ࠷ѱͷࣄଶ

    View full-size slide

  16. ਓ͕ؒ؅ཧ͢Δͷʹ͸ݶք͕͋Δ
    • ؾ߹͍͕͋Δ͏ͪ͸͍͍Μ͚ͩͲ
    • Ұ౓खΛൈ͘ͱ஍ࠈͰ͢
    • ΈΜͳେମ͍͍ՃݮͩΑͶ

    View full-size slide

  17. ͳͥ Git ͳͷ͔

    View full-size slide

  18. ͳͥ Git ͳͷ͔
    • ͍Ζ͍Ζཧ༝͸͋Γ·͕͢ɺ๻͸
    • GitHub ͕͋Δ
    • ΦʔϓϯιʔεͷίϥϘϨʔγϣϯ
    • Linus ͕࡞ͬͨ
    • ઃܭ͕γϯϓϧ
    • ͜ͷ 2 ͕ͭେ͖ͳϙΠϯτ͔ͳͬͯࢥ͍ͬͯ·͢

    View full-size slide

  19. ͸͡ΊΑ͏ Git
    Git Λར༻͢Δʹ͓֮͋ͨͬͯ͑ͯ͘ͱྑ͍ΩʔϫʔυͳͲͳͲ

    View full-size slide

  20. ͸͡Ίʹ
    • Git ͸ GUI ͷΞϓϦ΋͋Γ·͕͢ɺ࣮ࡍʹͲ͏͍͏͜
    ͱ͕ߦΘΕΔͷ͔ΛΠϝʔδͰ͖ΔΑ͏ʹͳΔͨΊʹɺ
    ͜ͷࢿྉͷதͰ͸ίϚϯυΛ͔ͭͬͯઆ໌͠·͢ɻ
    • GUI ΞϓϦͰͰ͖Δ͜ͱ͸ɺ͢΂ͯ͜ͷίϚϯυ·ͨ
    ͸ίϚϯυͷ૊Έ߹ΘͤͰ࣮ݱͰ͖·͢ɻ
    • ͱ͸͍͑ɺσβΠφʔͷํ͸ίϚϯυΛ೔ৗతʹ࢖Θ
    ͳ͍ਓ͕ଟ͍ͱࢥ͏ͷͰɺ࣮ࡍʹ͸Կ͔͠Βͷιϑτ
    ͷػೳΛ࢖͏͜ͱ͕ଟ͍ͷ͔ͳͱࢥ͍·͢ɻ

    View full-size slide

  21. ͸͡Ίʹ
    • ͜ͷ͓࿩͸ Git ೖ໳ͱͯ͠·͕͢ɺ͜ͷ࿩Λฉ͍ͨΒ
    Git ͕࢖͑ΔΑ͏ʹͳΔʂͱ͍͏ΑΓ͸ɺGit ͕Կऀͳ
    ͷ͔ͪΐͬͱ͚ͩΘ͔Δɻ͘Β͍ͷ͓࿩Ͱ͢ɻ
    • Git ͷٕज़తͳ͓࿩͸͠·ͤΜɻGit 2.0 ϦϦʔε͞Ε
    ͨͶʂͱ͔ͷτϐοΫ͸ग़͖ͯ·ͤΜɻ
    • ༻ޠͷਖ਼͠͞ΑΓɺ఻ΘΓ΍͢͞Λج४ʹݴ༿ΛબͿ
    ͜ͱ͕͋Γ·͢ɻݰਓ͸ͪΐͬͱͷ͍͋ͩզຫ͍ͯ͠
    ͍ͯͩ͘͞ɻ

    View full-size slide

  22. $
    ͯ͞ɺ͓ͳ͡Έͷࠇ͍ը໘Ͱ͢ɻ
    ͜ͷ $ ͸ɺίϚϯυೖྗΛ଴ػ͍ͯ͠Δ
    ঢ়ଶͩͱࢥ͍ͬͯͩ͘͞ɻ
    ʢͭ·ΓɺԿ΋ೖྗ͞Ε͍ͯͳ͍ɻͱ͍͏͜ͱͰ͢ʣ

    View full-size slide

  23. $ ls
    ͯ͞ɺ͓ͳ͡Έͷࠇ͍ը໘Ͱ͢ɻ
    ls ίϚϯυΛೖྗͨ͠ঢ়ଶͰ͢

    View full-size slide

  24. $ ls ↵
    ͯ͞ɺ͓ͳ͡Έͷࠇ͍ը໘Ͱ͢ɻ
    ΤϯλʔΩʔΛԡͨ͜͠ͱΛ໌֬ʹ͢ΔͨΊʹ
    ʮ ↵ ʯͷه߸Λ࢖͍ͬͯ·͢ɻ
    ʢࢿྉ಺ͰపఈͰ͖ͳ͍͔΋͠Εͳ͍͚Ͳ͝ΊΜʣ

    View full-size slide

  25. $ ls ↵
    hokkaido.jpg kitami.jpg kushiro.jpg
    sapporo.txt
    ͯ͞ɺ͓ͳ͡Έͷࠇ͍ը໘Ͱ͢ɻ
    ৽ͨͳߦʹදࣔ͞ΕΔͷ͕ ls ίϚϯυͷग़ྗ݁ՌͰ͢ɻ

    View full-size slide

  26. $ echo “ͦΕͰ͸ɺ࢝Ί·͢Αʂ" ↵
    ͦΕͰ͸ɺ࢝Ί·͢Αʂ

    View full-size slide

  27. !
    !
    !
    !
    !
    $ mkdir Ohotech
    ·ͣ͸ɺόʔδϣϯ؅ཧΛ͍ͨ͠σΟϨΫτϦʢϑΥϧ
    μʣΛ༻ҙ͠·͢ɻ΋ͪΖΜɺطʹ͋Δ΋ͷͰ΋͔·͍
    ·ͤΜɻ
    σΟϨΫτϦΛ࡞ΔίϚϯυ

    View full-size slide

  28. !
    !
    !
    !
    !
    $ mkdir Ohotech ↵
    $ cd Ohotech
    ·ͣ͸ɺόʔδϣϯ؅ཧΛ͍ͨ͠σΟϨΫτϦʢϑΥϧ
    μʣΛ༻ҙ͠·͢ɻ΋ͪΖΜɺطʹ͋Δ΋ͷͰ΋͔·͍
    ·ͤΜɻ
    σΟϨΫτϦΛ։͘ίϚϯυ

    View full-size slide

  29. !
    !
    !
    !
    !
    $ mkdir Ohotech ↵
    $ cd Ohotech ↵
    $ git init
    ·ͣ͸ɺόʔδϣϯ؅ཧΛ͍ͨ͠σΟϨΫτϦʢϑΥϧ
    μʣΛ༻ҙ͠·͢ɻ΋ͪΖΜɺطʹ͋Δ΋ͷͰ΋͔·͍
    ·ͤΜɻ
    σΟϨΫτϦͷྺ࢙Λ؅ཧ͠
    ࢝Ί·͢Αɺͱ͍͏એݴ

    View full-size slide

  30. !
    !
    !
    !
    !
    $ mkdir Ohotech ↵
    $ cd Ohotech ↵
    $ git init ↵
    Initialized empty Git repository in /path/to/
    Ohotech/.git/
    ·ͣ͸ɺόʔδϣϯ؅ཧΛ͍ͨ͠σΟϨΫτϦʢϑΥϧ
    μʣΛ༻ҙ͠·͢ɻ΋ͪΖΜɺطʹ͋Δ΋ͷͰ΋͔·͍
    ·ͤΜɻ
    /path/to/Ohotech/.git/ ʹۭͷϦϙδτϦ͕࡞੒͞Ε·͠
    ͨɻ
    “.” (υοτ) ͔Β࢝·ΔϑΝΠϧ໊͸ɺ௨ৗݟ͑ͳ
    ͍ϑΝΠϧͰ͢ (Windows ͸ؔ܎ͳ͍Ͱ͕͢)

    View full-size slide

  31. !
    !
    !
    !
    !
    $ ls ↵
    test.txt
    $ cat test.txt ↵
    This is a pan.
    $ git add test.txt ↵
    ࣍ʹɺԿ͔͠ΒͷϑΝΠϧΛ௥Ճͯ͠Έ·͠ΐ͏ɻ
    ͜͜Ͱ͸ “test.txt” ͱ͍͏ϑΝΠϧΛ࡞Γ·ͨ͠ɻ
    ← ϑΝΠϧͷத਎Λදࣔ͢ΔίϚϯυ
    “test.txt” Λ git Ͱ؅ཧ࢝͠Ί·͢Αɺͱ͍͏એݴ

    View full-size slide

  32. !
    !
    !
    !
    !
    $ git commit -m “test.txt Λ௥Ճ͠·ͨ͠” ↵
    ࣍ʹɺʮϑΝΠϧΛ௥Ճͨ͠ʯ͜ͱΛ git ʹه࿥ͤ͞·
    ͢ɻ
    git ϦϙδτϦͷঢ়ଶΛه࿥͢ΔίϚϯυ

    View full-size slide

  33. !
    !
    !
    !
    !
    $ git commit -m “test.txt Λ௥Ճ͠·ͨ͠” ↵
    ࣍ʹɺʮϑΝΠϧΛ௥Ճͨ͠ʯ͜ͱΛ git ʹه࿥ͤ͞·
    ͢ɻ
    มߋʹରͯ͠ίϝϯτΛ͚͍ͭͯ·͢ɻ

    View full-size slide

  34. !
    !
    !
    !
    !
    $ git commit -m “test.txt Λ௥Ճ͠·ͨ͠” ↵
    [master (root-commit) 026c173] test.txt Λ௥Ճ͠·
    ͨ͠
    1 file changed, 1 insertion(+)
    create mode 100644 test.txt
    ࣍ʹɺʮϑΝΠϧΛ௥Ճͨ͠ʯ͜ͱΛ git ʹه࿥ͤ͞·
    ͢ɻ
    1 ͭͷϑΝΠϧ͕มߋ͞Εɺ
    1 ߦ͕௥Ճ͞Ε·ͨ͠ɻ

    View full-size slide

  35. มߋΛه࿥͢Δͱ͍͏͜ͱ
    • جຊతʹ͸ɺ͜ͷҰ࿈ͷૢ࡞Λߦ͏͜ͱͰʮ͍ͭʯʮͩ
    Ε͕ʯʮͲͷΑ͏ͳʯมߋΛߦ͔ͬͨΛه࿥͢Δ͜ͱ
    ͕Ͱ͖·͢ɻ
    • ग़͖ͯͨίϚϯυ͸
    • git init - git ϦϙδτϦΛ࡞Δ
    • git add - ؅ཧ͢ΔϑΝΠϧΛ௥Ճ͢Δ
    • git commit - มߋΛه࿥͢Δ

    View full-size slide

  36. มߋΛه࿥͢Δͱ͍͏͜ͱ
    • ʮ͑ɺฅΊΜͲͤ͑͘…ʯͱࢥ͔ͬͨ΋͠Ε·ͤΜ͕ɺ
    ׳Ε·͢ɻ
    • Ή͠Ζ git ͕ͳ͍ͱෆ҆ʹͳΓ·͢ɻ
    • มߋ͕ه࿥͞Εͳ͍ͳΜͯɺා͍…ʂ
    • มߋ͕ه࿥͞Ε͍ͯΔͱ͍͏͜ͱ͸ɺ͍ͭͰ΋ͦͷه࿥
    ʹ໭ΕΔͱ͍͏͜ͱͰ͢ɻ
    • ήʔϜͰ΋ॏཁͳηʔϒϙΠϯτͰ͢Ͷɻηʔϒ͠ͳ͍༐
    ऀ΋ډΔ͔΋͠Ε·ͤΜ͕ɻ

    View full-size slide

  37. !
    !
    $ cat test.txt ↵
    This is a pan.
    !
    !
    pan Ͱ͸ͳ͘ pen ͩͬͨ͜ͱʹؾ͕͖ͭ·ͨ͠ɻ

    View full-size slide

  38. !
    !
    $ cat test.txt ↵
    This is a pan.
    !
    !
    !
    $ cat test.txt ↵
    This is a ΃Μ.
    pan Ͱ͸ͳ͘ pen ͩͬͨ͜ͱʹؾ͕͖ͭ·ͨ͠ɻ
    ௚ͯ͠Έ·͢ɻ

    View full-size slide

  39. !
    !
    $ cat test.txt ↵
    This is a pan.
    !
    !
    !
    $ cat test.txt ↵
    This is a ΃Μ.
    !
    !
    !
    !
    $ git checkout test.txt ↵
    $ cat test.txt ↵
    This is a pan.
    pan Ͱ͸ͳ͘ pen ͩͬͨ͜ͱʹؾ͕͖ͭ·ͨ͠ɻ
    ௚ͯ͠Έ·͢ɻ
    ͪΌΜͱ௚ͨͭ͠΋Γ͕ɺͳΜ͔ؒҧ͍͑ͯ·ͨ͠ɻ
    ͍ͬͨΜ࠷ॳͷঢ়ଶʹ໭ͨ͘͠ͳΓ·ͨ͠ɻ

    View full-size slide

  40. !
    !
    $ cat test.txt ↵
    This is a pen.
    !
    !
    ͜ΜͲ͸ͪΌΜͱ௚ͦ͏ͱࢥ͍·͢ɻ

    View full-size slide

  41. !
    !
    $ cat test.txt ↵
    This is a pen.
    !
    !
    !
    $ git add test.txt ↵
    $ git commit -m “৯ཉશ։ͩͬͨͷͰमਖ਼͠·ͨ͠” ↵
    [master 25ea33c] ৯ཉશ։ͩͬͨͷͰमਖ਼͠·ͨ͠
    1 file changed, 1 insertion(+), 1 deletion(-)
    ͜ΜͲ͸ͪΌΜͱ௚ͦ͏ͱࢥ͍·͢ɻ
    มߋΛه࿥͠·͢ɻϑΝΠϧͷ௥ՃͱҰॹͰ͢ɻ

    View full-size slide

  42. !
    !
    !
    !
    $ git log ↵
    commit 25ea33ceace1a46c258d7119281164427ab0cebd
    Author: Keisuke SATO
    Date: Fri May 30 20:44:03 2014 +0900
    !
    ৯ཉશ։ͩͬͨͷͰमਖ਼͠·ͨ͠
    !
    commit 026c173f1e8bc13a6fc0a7116792a32feb9dd31f
    Author: Keisuke SATO
    Date: Fri May 30 20:28:02 2014 +0900
    !
    test.txt Λ௥Ճ͠·ͨ͠
    ͜͜Ͱɺࠓ·Ͱ͜ͷϦϙδτϦͰͲͷΑ͏ͳมߋ͕ߦΘ
    Ε͍ͯͨͷ͔Λ֬ೝͨ͘͠ͳͬͨͱ͠·͢ɻ
    ίϛοτ͸ϋογϡ஋Ͱه࿥͞Ε͍ͯ·͢ɻ
    มߋΛಛఆ͢Δ ID ͷ༻ͳ΋ͷͰ͢ɻ
    ʮ25ea33c… ͷίϛοτʯ

    View full-size slide

  43. !
    !
    !
    $ git show 25ea33ceace1a46c258d7119281164427ab0cebd ↵
    commit 25ea33ceace1a46c258d7119281164427ab0cebd
    Author: Keisuke SATO
    Date: Fri May 30 20:44:03 2014 +0900
    !
    ৯ཉશ։ͩͬͨͷͰमਖ਼͠·ͨ͠
    !
    diff --git a/test.txt b/test.txt
    index a938556..149bbea 100644
    --- a/test.txt
    +++ b/test.txt
    @@ -1 +1 @@
    -This is a pan.
    +This is a pen.
    ͯ͞ɺͦͷมߋ͸ԿΛߦͬͨͷͰ͠ΐ͏͔ɻ

    View full-size slide

  44. มߋΛه࿥͢Δͱ͍͏͜ͱ
    • ه࿥͞Εͨมߋ͸ɺޙ͔Β͔͞ͷ΅ͬͯ֬ೝ͢Δ͜ͱ
    ͕Ͱ͖·͢ɻ
    • ͓͔͠ͳ͜ͱ͕͓ͬͯ͜΋؆୯ʹಛఆͰ͖·͢ɻ
    • ͜ͷޡࣈɺ͍͔ͭΒͩʂʁ
    • લ͸େৎ෉ͩͬͨͷʹͳΜ͔͓͔͘͠ͳͬͨʂ

    View full-size slide

  45. ͜Ε·Ͱͷ͓͞Β͍
    • ϦϙδτϦΛ࡞ͬͯ (git init)
    • ϑΝΠϧΛ௥Ճͯ͠ (git add)
    • มߋΛه࿥͢Δ (git commit)
    • ه࿥ͨ͠ϑΝΠϧʹஔ͖׵͑Δ (git checkout)
    • ޙ͔ΒมߋΛ֬ೝ͢Δ (git log / git show)

    View full-size slide

  46. ΈΜͳͰ࢖͏ Git

    View full-size slide

  47. 1ਓͰ࢖͏ͷ΋͍͍ΜͰ͕͢
    • όʔδϣϯ؅ཧͷྗΛ΋ͬͱ׆༻͢Δʹ͸΍ͬͺΓෳ
    ਺ਓͰ͍Ζ͍Ζ͍͡Δͱ͖Ͱ͢ɻ
    • ͔͜͜Β͸࣮ࡍͷಈ࡞ͱ͍͏ΑΓ͸ɺ׆༻͢ΔΠϝʔ
    δΛϝΠϯʹෳ਺ਓͰ Git Λ࢖͏ͱ͖ͷ͓࿩Λ͠·͢ɻ
    • ࣮ࡍʹ΍Δ͜ͱ͸جຊతʹ͜Ε·Ͱग़͖ͯͨ͜ͱ͕΄
    ͱΜͲͰ͢ɻ

    View full-size slide

  48. มߋͷྺ࢙
    git init
    มߋ A
    มߋ B

    View full-size slide

  49. ϒϥϯν
    A
    B
    A’
    B’
    • git branch

    View full-size slide

  50. ϒϥϯνͷϚʔδ
    A
    B
    A’
    B’
    C (A’, B’)
    • git merge

    View full-size slide

  51. rebase
    A
    B
    A’
    B’
    • git rebase
    • Ͳͷίϛοτ͔Βϒϥϯ
    νΛ࡞੒ͨ͠ͷ͔ɺΛվ
    ͟Μ͢Δ

    View full-size slide

  52. rebase
    A
    B
    A’
    B’
    • git rebase
    • Ͳͷίϛοτ͔Βϒϥϯ
    νΛ࡞੒ͨ͠ͷ͔ɺΛվ
    ͟Μ͢Δ

    View full-size slide

  53. ಉ࣌ʹ͍ΖΜͳมߋ͕Ͱ͖ͯศརͳͷ͸ྑ͍͕ɺ
    Ͳ͏΍ͬͯڞ༗͢ΜͶΜɻ

    View full-size slide

  54. ϦϙδτϦΛڞ༗͢Δ

    View full-size slide

  55. ϦϙδτϦΛڞ༗͢Δ
    Pull
    Push

    View full-size slide

  56. ϦϙδτϦΛڞ༗͢Δ
    Pull
    Push

    View full-size slide

  57. ϦϙδτϦΛڞ༗͢Δ

    View full-size slide

  58. ϦϙδτϦΛڞ༗͢Δ

    View full-size slide

  59. Git ΛΠϯετʔϧ͍ͨ͠

    View full-size slide

  60. Mac OSX
    • σϑΥϧτͰೖͬͯΔΜ͡Όͳ͍Ͱ͔͢Ͷɻ
    • ΋͔ͨ͠͠Β Xcode ΛΠϯετʔϧ͢Δඞཁ͕͋Δ
    ͔΋ʁ
    • ΋͠ɺ৽͍͠όʔδϣϯΛೖΕ͍ͨͱ͔Ͱ͋Ε͹ɺ
    Homebrew Λ࢖͑͹؆୯ʹΠϯετʔϧͰ͖·͢ɻ
    • GitHub for Mac, SourceTree for Mac

    View full-size slide

  61. Linux
    • apt-get install git
    • ׬શʹσΟετϦϏϡʔγϣϯΛݶఆ͍ͯ͠Δ

    View full-size slide

  62. Windows
    • ެࣜʹ͸αϙʔτ͞Εͯ·ͤΜ
    • Git for Windows (msysGit)
    • SourceTree for Windows
    • GitHub for Windows

    View full-size slide

  63. ͓͞Β͍
    • git
    • init, add, commit, checkout, log, show, pull, push,
    branch, rebase
    • GitHub
    • PullRequest ͸࠷ߴʹྑ͍
    • ๺ւಓେ޷͖

    View full-size slide

  64. # shutdown -h now ↵
    Broadcast message from root (pts/1) (Sat May 31
    17:32:16 2014):
    The system is going down for reboot NOW!

    View full-size slide