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. @riaf ࠤ౻Ղ༞ (Keisuke SATO) 1987/9/16 ! ๺ւಓ۴࿏ग़਎ ۴࿏ބྕ → ๺ݟ޻ۀେֶ

    ! Co-Founder and Engineer at Crocos Inc. ! LOCAL Japan PHP Users Group Sapporo.php ! Love Ohotech !
  2. ͳͥ Git ͳͷ͔ • ͍Ζ͍Ζཧ༝͸͋Γ·͕͢ɺ๻͸ • GitHub ͕͋Δ • ΦʔϓϯιʔεͷίϥϘϨʔγϣϯ

    • Linus ͕࡞ͬͨ • ઃܭ͕γϯϓϧ • ͜ͷ 2 ͕ͭେ͖ͳϙΠϯτ͔ͳͬͯࢥ͍ͬͯ·͢
  3. ͸͡Ίʹ • Git ͸ GUI ͷΞϓϦ΋͋Γ·͕͢ɺ࣮ࡍʹͲ͏͍͏͜ ͱ͕ߦΘΕΔͷ͔ΛΠϝʔδͰ͖ΔΑ͏ʹͳΔͨΊʹɺ ͜ͷࢿྉͷதͰ͸ίϚϯυΛ͔ͭͬͯઆ໌͠·͢ɻ • GUI

    ΞϓϦͰͰ͖Δ͜ͱ͸ɺ͢΂ͯ͜ͷίϚϯυ·ͨ ͸ίϚϯυͷ૊Έ߹ΘͤͰ࣮ݱͰ͖·͢ɻ • ͱ͸͍͑ɺσβΠφʔͷํ͸ίϚϯυΛ೔ৗతʹ࢖Θ ͳ͍ਓ͕ଟ͍ͱࢥ͏ͷͰɺ࣮ࡍʹ͸Կ͔͠Βͷιϑτ ͷػೳΛ࢖͏͜ͱ͕ଟ͍ͷ͔ͳͱࢥ͍·͢ɻ
  4. ͸͡Ίʹ • ͜ͷ͓࿩͸ Git ೖ໳ͱͯ͠·͕͢ɺ͜ͷ࿩Λฉ͍ͨΒ Git ͕࢖͑ΔΑ͏ʹͳΔʂͱ͍͏ΑΓ͸ɺGit ͕Կऀͳ ͷ͔ͪΐͬͱ͚ͩΘ͔Δɻ͘Β͍ͷ͓࿩Ͱ͢ɻ •

    Git ͷٕज़తͳ͓࿩͸͠·ͤΜɻGit 2.0 ϦϦʔε͞Ε ͨͶʂͱ͔ͷτϐοΫ͸ग़͖ͯ·ͤΜɻ • ༻ޠͷਖ਼͠͞ΑΓɺ఻ΘΓ΍͢͞Λج४ʹݴ༿ΛબͿ ͜ͱ͕͋Γ·͢ɻݰਓ͸ͪΐͬͱͷ͍͋ͩզຫ͍ͯ͠ ͍ͯͩ͘͞ɻ
  5. ! ! ! ! ! $ mkdir Ohotech ↵ $

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

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

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

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

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

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

    Λ௥Ճ͠·ͨ͠” ↵ [master (root-commit) 026c173] test.txt Λ௥Ճ͠· ͨ͠ 1 file changed, 1 insertion(+) create mode 100644 test.txt ࣍ʹɺʮϑΝΠϧΛ௥Ճͨ͠ʯ͜ͱΛ git ʹه࿥ͤ͞· ͢ɻ 1 ͭͷϑΝΠϧ͕มߋ͞Εɺ 1 ߦ͕௥Ճ͞Ε·ͨ͠ɻ
  12. มߋΛه࿥͢Δͱ͍͏͜ͱ • ʮ͑ɺฅΊΜͲͤ͑͘…ʯͱࢥ͔ͬͨ΋͠Ε·ͤΜ͕ɺ ׳Ε·͢ɻ • Ή͠Ζ git ͕ͳ͍ͱෆ҆ʹͳΓ·͢ɻ • มߋ͕ه࿥͞Εͳ͍ͳΜͯɺා͍…ʂ

    • มߋ͕ه࿥͞Ε͍ͯΔͱ͍͏͜ͱ͸ɺ͍ͭͰ΋ͦͷه࿥ ʹ໭ΕΔͱ͍͏͜ͱͰ͢ɻ • ήʔϜͰ΋ॏཁͳηʔϒϙΠϯτͰ͢Ͷɻηʔϒ͠ͳ͍༐ ऀ΋ډΔ͔΋͠Ε·ͤΜ͕ɻ
  13. ! ! $ cat test.txt ↵ This is a pan.

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

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

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

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

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

    Author: Keisuke SATO <riaf@me.com> 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. ͯ͞ɺͦͷมߋ͸ԿΛߦͬͨͷͰ͠ΐ͏͔ɻ
  20. ͜Ε·Ͱͷ͓͞Β͍ • ϦϙδτϦΛ࡞ͬͯ (git init) • ϑΝΠϧΛ௥Ճͯ͠ (git add) •

    มߋΛه࿥͢Δ (git commit) • ه࿥ͨ͠ϑΝΠϧʹஔ͖׵͑Δ (git checkout) • ޙ͔ΒมߋΛ֬ೝ͢Δ (git log / git show)
  21. Mac OSX • σϑΥϧτͰೖͬͯΔΜ͡Όͳ͍Ͱ͔͢Ͷɻ • ΋͔ͨ͠͠Β Xcode ΛΠϯετʔϧ͢Δඞཁ͕͋Δ ͔΋ʁ •

    ΋͠ɺ৽͍͠όʔδϣϯΛೖΕ͍ͨͱ͔Ͱ͋Ε͹ɺ Homebrew Λ࢖͑͹؆୯ʹΠϯετʔϧͰ͖·͢ɻ • GitHub for Mac, SourceTree for Mac
  22. ͓͞Β͍ • git • init, add, commit, checkout, log, show,

    pull, push, branch, rebase • GitHub • PullRequest ͸࠷ߴʹྑ͍ • ๺ւಓେ޷͖
  23. # shutdown -h now ↵ Broadcast message from root (pts/1)

    (Sat May 31 17:32:16 2014): The system is going down for reboot NOW!