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

Git講習 2014.04.15

Git講習 2014.04.15

Held at UEC

masawada

April 15, 2014
Tweet

More Decks by masawada

Other Decks in Programming

Transcript

  1. Gitߨश
    2014.04.15

    View full-size slide

  2. ߨࢣ ঺հ
    • masawada
    • ৘ใཧ޻ֶ෦ ৘ใɾ௨৴޻ֶՊ 3೥

    ίϯϐϡʔλαΠΤϯείʔε
    • Θ͔Βͳ͍͜ͱ͕͋Ε͹

    [email protected]·ͨ͸

    @masawada (Twitter) ·Ͱ

    View full-size slide

  3. ຊ೔ͷ͓͠ͳ͕͖
    • Gitͱ͸
    • جຊతͳίϚϯυ / ߟ͑ํ
    • Gitͷத਎ΛΈͯΈΑ͏

    View full-size slide

  4. ߨशΛߦ͏ʹ͋ͨͬͯ
    • ࣮ࡍʹίϚϯυΛଧͪͳ͕Βઆ໌͠·͢ɻ
    • Մೳͳํ͸͓खݩͷ୺຤Ͱ͓ࢼ͍ͩ͘͠͞ɻ
    • ࢿྉ͸WebαΠτʹΞοϓϩʔυ͞Ε͍ͯ·͢ɻ

    View full-size slide

  5. Gitͱ͸
    όʔδϣϯ؅ཧγεςϜ (VCS)

    = มߋཤྺΛه࿥ / ؅ཧ͢Διϑτ΢ΣΞ
    !
    ଞʹ΋Subversion΍BazzarͳͲ…

    View full-size slide

  6. ྫ͑͹
    • Ϩϙʔτ΍ϓϩάϥϜΛॻ͍͍ͯͯ

    ۠੾Γͷྑ͍ͱ͜ΖͰอଘ͓͖͍ͯͨ͠
    • ·ͱ΋ʹॻ͚͍ͯΔ / ಈ͍͍ͯΔঢ়ଶͷ΋ͷΛ

    อଘ͓͍ͯ͠ɺ໰୊͕ൃੜͨ͠ͱ͖ʹ

    ໭ͤΔΑ͏ʹ͍ͨ͠

    View full-size slide

  7. ͍··Ͱͷ
    มߋཤྺ؅ཧ

    View full-size slide

  8. ϑΝΠϧϕʔε

    View full-size slide

  9. खಈͰมߋཤྺΛ؅ཧ͢ΔͷͰ
    ਓҝతͳϛε͕ଟ͘ͳΔ
    ͜ΕΒΛ͢΂ͯ
    ࣗಈԽ͍ͨ͠

    View full-size slide

  10. ͱ͍͏ߟ͑ͷ΋ͱੜ·Εͨͷ͕
    όʔδϣϯ؅ཧγεςϜ

    View full-size slide

  11. ɾҰ೥࣍ޙظͷجૅϓϩάϥϛϯά͓Αͼԋश
    → Cݴޠͷॻ͖ํΛֶͿ
    → มߋཤྺΛ؅ཧ͢Δඞཁ͕͋·Γͳ͍
    !
    !
    ɾຊϫʔΫγϣοϓ
    → ಈ͘ϞϊΛ࡞Δ
    → มߋཤྺΛ؅ཧ͢Δඞཁ͕͋Δ

    View full-size slide

  12. جૅฤ
    • ϦϙδτϦ (repository)
    • ίϛοτ (commit)

    View full-size slide

  13. ϦϙδτϦͱ͸
    σʔλͷมߋཤྺΛ؅ཧ͢Δ
    ா฽ͷΑ͏ͳ΋ͷ

    View full-size slide

  14. ίϛοτͱ͸
    ϦϙδτϦʹରͯ͠
    มߋཤྺΛ௥Ճ͢Δ͜ͱ

    View full-size slide

  15. ίϛοτ࡞੒ͷྲྀΕ
    1. ϫʔΫπϦʔͰϑΝΠϧΛ௥Ճ/มߋ/࡟আ͢Δ
    2. ͋Δఔ౓·ͱ·ͬͨΒΠϯσοΫεʹ௥Ճ͢Δ

    ΠϯσοΫεͱ͸ɺػೳ͝ͱͳͲʹ෼͚ͯίϛοτΛ

    ࡞ΔͨΊʹมߋͨ͠ϑΝΠϧΛཷΊΔ৔ॴ

    ΠϯσοΫεʹొ࿥͞Ε͍ͯͳ͍ϑΝΠϧ͸ίϛοτ͞Εͳ͍
    3. ΠϯσοΫεͷ಺༰ΛϦϙδτϦʹίϛοτ͢Δ

    View full-size slide

  16. ϦϙδτϦͱίϛοτ
    ϫʔΫπϦʔ ΠϯσοΫε ϦϙδτϦ
    (࡞ۀσΟϨΫτϦ)

    View full-size slide

  17. ϦϙδτϦͷॳظԽ
    $ git init

    View full-size slide

  18. ΠϯσοΫεʹมߋΛొ࿥
    $ git add [filename]
    $ git add .

    View full-size slide

  19. ίϛοτͷ࡞੒
    $ git commit
    $ git commit -m “message”

    View full-size slide

  20. ϑΝΠϧͷঢ়ଶΛදࣔ
    $ git status

    View full-size slide

  21. มߋཤྺͷදࣔ
    $ git log

    View full-size slide

  22. ͜͜·ͰΛσϞ

    View full-size slide

  23. ࠩ෼ͷදࣔ
    $ git diff [old] [new]

    View full-size slide

  24. ͜͜·ͰΛσϞ

    View full-size slide

  25. ϒϥϯνͱ͸

    View full-size slide

  26. ϒϥϯνͱ͸
    ࢧ෦, ࢧہ

    View full-size slide

  27. ϒϥϯνͱ͸
    • ෳ਺ͷػೳΛಉ࣌ʹฒߦͯ͠࡞੒Ͱ͖Δ
    • νʔϜ։ൃΛ͢Δͱ͖ʹϒϥϯνΛ࡞Δ͜ͱͰ

    ଞਓͷมߋʹ໎࿭Λ͔͚ͳ͍Α͏࡞ۀͰ͖Δ
    • ෆ҆ͳ࡞ۀ͸ϒϥϯνΛ࡞͔ͬͯΒߦ͏͜ͱͰ

    ϒϥϯνΛফ͚ͩ͢Ͱݩͷঢ়ଶʹ໭ΕΔ

    View full-size slide

  28. ϒϥϯνͱ͸

    View full-size slide

  29. ϒϥϯνͷ࡞੒
    $ git branch [name]

    View full-size slide

  30. ϒϥϯνͷ৐Γ׵͑
    $ git checkout [name]

    View full-size slide

  31. ϒϥϯνͷ࡞੒ͱ৐Γ׵͑
    $ git checkout -b [name]

    View full-size slide

  32. ϒϥϯνͷ౷߹
    $ git merge [name]

    View full-size slide

  33. ϒϥϯνͷ࡟আ
    $ git branch -d [name]
    $ git branch -D [name]
    merge͞Ε͍ͯͳ͍ϒϥϯν͸-DͰফ͢

    View full-size slide

  34. ͜͜·ͰΛσϞ

    View full-size slide

  35. ϒϥϯνͷڝ߹

    View full-size slide

  36. ϒϥϯνͷڝ߹
    1. master͔Βfeature_1, feature_2ϒϥϯνΛ࡞੒
    2. feature_1ϒϥϯνʹػೳΛ௥Ճɺίϛοτ͢Δ
    3. feature_1ϒϥϯνΛmasterϒϥϯνʹmerge
    4. feature_2ϒϥϯνʹػೳΛ௥Ճɺίϛοτ͢Δ
    5. feature_2ϒϥϯνΛmasterϒϥϯνʹmerge

    View full-size slide

  37. ϒϥϯνͷڝ߹
    master
    feature_1
    feature_2

    View full-size slide

  38. ࣮ࡍʹσϞ

    View full-size slide

  39. ϦϞʔτϦϙδτϦ

    View full-size slide

  40. ϦϞʔτϦϙδτϦ
    • ϦϙδτϦΛαʔόʹόοΫΞοϓ
    • ϦϙδτϦΛଞਓͱڞ༗Ͱ͖Δ

    View full-size slide

  41. GitϦϙδτϦ
    ϗεςΟϯάαʔϏε

    View full-size slide

  42. ϦϞʔτϦϙδτϦͷొ࿥
    $ git remote add [name] [url]

    View full-size slide

  43. ϦϞʔτϦϙδτϦͷऔಘ
    $ git clone [url]

    View full-size slide

  44. ϦϞʔτϦϙδτϦͷߋ৽
    $ git push
    $ git push -u [name] [branch]

    View full-size slide

  45. ϩʔΧϧϦϙδτϦͷߋ৽
    $ git pull

    View full-size slide

  46. ͜͜·ͰΛσϞ

    View full-size slide

  47. ίϛοτͷ
    औΓফ͠/΍Γ௚͠

    View full-size slide

  48. ௚લͷίϛοτͷ΍Γͳ͓͠
    $ git commit --amend
    ͻͱͭ·͑ͷίϛοτΛ΍Γͳ͓͢

    View full-size slide

  49. ΠϯσοΫε௥ՃͷऔΓফ͠
    $ git reset
    ΠϯσοΫεʹ௥Ճͨ͠ϑΝΠϧͷϦετΛ
    ΠϯσοΫε͔ΒऔΓআ͘

    View full-size slide

  50. ίϛοτͷ࡟আ
    $ git reset --hard [commit]
    ࢦఆͨ͠ίϛοτ·Ͱ໭Δ
    ࢦఆίϛοτ͔Βݱࡏ·Ͱͷίϛοτ͸࢒Βͳ͍

    View full-size slide

  51. ίϛοτͷ࡟আ
    $ git reset --soft [commit]
    ࢦఆͨ͠ίϛοτ·Ͱ໭Δ
    ϫʔΫπϦʔͷมߋཤྺ͸࢒Δ

    View full-size slide

  52. ίϛοτͷଧͪফ͠
    $ git revert [commit]
    ࢦఆͨ͠ίϛοτΛଧͪফ͢ίϛοτΛ࡞੒͢Δ
    ͦͷίϛοτͰ௥Ճͨ͠෦෼Λͬͦ͝Γ࡟আ͢Δ

    View full-size slide

  53. ͜͜·ͰΛσϞ

    View full-size slide

  54. ͦͷଞͷTips

    View full-size slide

  55. .gitignore
    .DS_Store΍.swpͳͲͷ͍Βͳ͍ϑΝΠϧΛ
    ௥Ճ͠ͳ͍Α͏ʹͰ͖Δ

    View full-size slide

  56. ͜͜·ͰΛσϞ

    View full-size slide

  57. ·ͩ·ͩػೳ͸
    ͨ͘͞Μ͋Δ

    View full-size slide

  58. ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View full-size slide