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

Git ハンズオン Part 1 / Git Handson Part 1

takasp
September 25, 2018
55

Git ハンズオン Part 1 / Git Handson Part 1

takasp

September 25, 2018
Tweet

More Decks by takasp

Transcript

  1. ຊ೔ѻ͏ Git ίϚϯυ • git add • git commit •

    git push • git branch • git status • git merge • git init • git log • git clone • git pull • git diff • git config • git checkout
  2. ϑΝΠϧΛ؅ཧ͢Δ • ԿΛ؅ཧ͍ͨ͠ͷ͔ʁ • ୭͕ʁ • ͍ͭʁ • ͲͷϑΝΠϧΛʁ •

    ԿΛมߋͨ͠ʁ JOEFY@࠷ऴ൛IUNM JOEFY@࠷ऴ൛IUNM JOEFY@OFXIUNM JOEFY@OFXIUNM JOEFY@IUNM JOEFY@IUNM JOEFY@IUNM JOEFYIUNM
  3. Git Λ࢖ͬͨྲྀΕ 1 )5.-ϑΝΠϧ Λ௥Ճ commit1 HEAD ద੾ͳίϛοτ
 ϝοηʔδΛ͚ͭΔ HEAD:


    ݱࡏΛࢦࣔ͢͠࡞ۀঢ়ଶ commit:
 มߋͷཤྺΛه࿥ͨ͠΋ͷ
  4. Git Λ࢖ͬͨྲྀΕ 1 2 )5.-ϑΝΠϧ Λ௥Ճ JNHλάΛ௥Ճ commit1 commit2 HEAD

    ίϛοτΛ௥Ճͨ͠ ίϛοτΛ௥Ճ͢Δͱ
 HEAD͕ਐΉ
  5. Git Λ࢖ͬͨྲྀΕ 1 2 3 )5.-ϑΝΠϧ Λ௥Ճ JNHλάΛ௥Ճ UJUMFΛมߋ commit1

    commit2 commit3 HEAD ίϛοτΛ௥Ճͨ͠ ߋʹHEAD͕ਐΉ
  6. Git Λ࢖ͬͨྲྀΕ 1 2 3 4 )5.-ϑΝΠϧ Λ௥Ճ JNHλάΛ௥Ճ UJUMFΛมߋ

    DTTΛमਖ਼ HEAD commit1 commit2 commit3 commit4 ίϛοτΛաڈʹ ḪΔ͜ͱ΋Ͱ͖Δ
  7. ϒϥϯν 1 2 3 4 merge merge:
 ϒϥϯνಉ࢜Λ ݁߹͢Δػೳ 2

    5 feature ϒϥϯν΍ fix ϒϥϯν ϝΠϯͷϒϥϯν branch:
 ཤྺΛࢬ෼͔Εͤͯ͞ ه࿥͢Δػೳ
  8. ෼ࢄܕͱूதܕ தԝϦϙδτϦ ϦϞʔτϦϙδτϦ ूதܕ ෼ࢄܕ ొ࿥ ొ࿥ औಘ औಘ ొ࿥

    औಘ ίϛοτ ొ࿥ औಘ ίϛοτ ϩʔΧϧ
 ϦϙδτϦ ϩʔΧϧ
 ϦϙδτϦ
  9. ࠷௿ݶ͓͖͍֮͑ͯͨ
 Linux ίϚϯυ • pwd (print working directory) : ݱࡏͷσΟϨΫτϦΛදࣔ͢Δ

    • cd (change directory) : ଞͷσΟϨΫτϦʹҠಈ͢Δ • ls (list) : ݱࡏͷσΟϨΫτϦͷσΟϨΫτϦ΍ϑΝΠϧΛදࣔ͢Δ • mkdir (make directory) : σΟϨΫτϦΛ࡞੒͢Δ • mv (move) : ϑΝΠϧΛҠಈ͢Δ • cp (copy) : ϑΝΠϧΛίϐʔ͢Δ • rm (remove) : ϑΝΠϧ΍σΟϨΫτϦΛ࡟আ͢Δ
  10. git config Ͱઃఆ͠Α͏ • Ϣʔβʔ৘ใΛઃఆ͢Δ • editor ͷઃఆʢVisual Studio Code

    Ͱىಈ͢Δྫʣ • ઃఆΛ֬ೝ͢Δ
 git config --global user.name takasp
 git config --global user.email [email protected] git config --global core.editor "code --wait" git config --global --list
  11. ϑΝΠϧΛ࡞੒͢Δ • ҎԼͷςΩετΛؚΉ README.md ϑΝΠϧ Λ࡞੒͢Δ # Git
 ॳΊͯͷ Git

    ϑΝΠϧͰ͢ɻ ൒֯εϖʔε 2 ݸΛ
 ޙΖʹೖΕ͓ͯ͘ͱվߦʹͳΔ
 (markdown ه๏)
  12. ঢ়ଶΛ֬ೝ͢Δ • git status ίϚϯυͰݱࡏͷঢ়ଶΛ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ git status README.md

    ϑΝΠϧ͕௥੻͞Ε͍ͯͳ͍ ݱࡏ master ϒϥϯνʹ͍Δ ࠔͬͨΒ͙͢ʹHJUTUBUVTΛ͢Δ͜ͱʂ
 ݱࡏʹର͢Δඞཁͳ͜ͱΛڭ͑ͯ͘ΕΔ
  13. ίϛοτ͢Δ • git commit ίϚϯυͰίϛοτ͢Δ git commit -m 'READMEΛ௥Ճͨ͠' NΦϓγϣϯ͸ίϛοτϝοηʔδΛࢦఆ͢Δ

    NΦϓγϣϯΛࢦఆ͠ͳ͍৔߹͸ɺ
 DPSFFEJUPSͰઃఆͨ͠ΤσΟλΛىಈ͢Δ ίϛοτ
 ϝοηʔδΛ
 ࢦఆ͢Δ
  14. ࠶౓ϑΝΠϧΛมߋ͢Δ • README.md ʹҎԼͷςΩετΛ௥Ճ͢Δ # Git
 ॳΊͯͷ Git ϑΝΠϧͰ͢ɻ 


    ଓ͍ͯ௥ՃͷίϛοτΛߦ͍·͢ɻ ௥ՃߦͷςΩετ ൒֯εϖʔε 2 ݸΛ
 ޙΖʹೖΕΔ
  15. git add ίϚϯυͷิ଍ • git add . ͰΧϨϯτσΟϨΫτϦҎԼͷϑΝΠϧશͯ ΛεςʔδʹҠಈ͢Δ
 •

    -A ·ͨ͸ --all ΦϓγϣϯͰมߋͨ͠ϑΝΠϧ΍৽نͰ ࡞੒ͨ͠ϑΝΠϧΛશͯεςʔδʹҠಈ͢Δ • εςʔδʹҠಈ͍ͨ͠ϑΝΠϧΛ֬ೝ͍ͨ͠৔߹͸ɺ git status Ͱ֬ೝ͠ͳ͕Β֤ϑΝΠϧΛҠಈ͢Δͱྑ͍ git add . ϐϦΦυ͸ΧϨϯτσΟϨΫτϦΛҙຯ͢Δ
  16. git commit ίϚϯυͷิ଍ • git commit . ͰσΟϨΫτϦ഑Լͷط஌ͷ
 ϑΝΠϧΛશͯίϛοτ͢Δ 


    ※ ৽نϑΝΠϧ͸ؚ·ͳ͍ • git commit -a ط஌ͷϑΝΠϧΛશͯίϛοτ͢Δ
 ˞ ৽نϑΝΠϧ͸ؚ·ͳ͍ • git commit -am '<MSG>' Ͱมߋͷ͋ΔϑΝΠϧΛίϛοτ ϝοηʔδ෇͖ͰίϛοτͰ͖Δ
  17. ͜Ε·Ͱͷ·ͱΊ ͦͷ1 • git init : ϩʔΧϧϦϙδτϦΛ࡞੒͢Δ • git add

    : εςʔδϯάʹϑΝΠϧΛ௥Ճ͢Δ • git commit : ͦͷ࣌఺Λه࿥͢Δ • git diff : ࠩ෼ΛݟΔ • git status : ݱࡏͷঢ়ଶΛݟΔ • git log : ݱࡏͷίϛοτϩάΛݟΔ
  18. • git branch ίϚϯυͰϒϥϯνΛ֬ೝ͢Δ • ͢ΔͱҎԼͷΑ͏ͳද͕ࣔ͞ΕΔ • ΋͘͠͸ git status

    ίϚϯυͰ΋֬ೝͰ͖Δ
 ੾Γସ͑ͨϒϥϯνΛ֬ೝ͢Δ git branch task1 ϒϥϯν੾ΓସΘ͍ͬͯΔ͜ͱ͕Θ͔Δ task1 ϒϥϯνͰ͋Δ͜ͱ͕Θ͔Δ
  19. ϒϥϯνΛ࡞੒ͯ͠੾Γସ͑Δ • git checkout ίϚϯυͰϒϥϯνΛ࡞੒ͯ͠
 ੾Γସ͑Δ git checkout -b task2

    ࡞ۀΛ࢝ΊΔͱ͖͸ɺ
 checkout ίϚϯυͱ
 -b ΦϓγϣϯΛ
 Α͘࢖͏ Cࢦఆͨ͠ϒϥϯνΛ࡞੒ͯ͠੾Γସ͑Δ
  20. ϑΝΠϧΛมߋ͢Δ • README.md ʹҎԼͷςΩετΛ௥Ճ͢Δ # Git
 ॳΊͯͷ Git ϑΝΠϧͰ͢ɻ 


    ଓ͍ͯ௥ՃͷίϛοτΛߦ͍·͢ɻ 
 ଓ͍ͯϚʔδΛߦ͍·͢ɻ ௥ՃߦͷςΩετ ൒֯εϖʔε 2 ݸΛ
 ޙΖʹೖΕΔ
  21. master ϒϥϯνʹมߋΛ
 Ϛʔδ͢Δ • git merge ίϚϯυͰ master ϒϥϯνʹ
 task2

    ϒϥϯνΛ౷߹͢Δ git merge task2 ϚʔδݩͷϒϥϯνΛࢦఆ͢Δͱ ݱࡏͷϒϥϯνʹϚʔδ͞ΕΔ
  22. ͜Ε·Ͱͷ·ͱΊ ͦͷ2 • git branch : ϒϥϯνΛ࡞੒ͨ͠Γɺϒϥϯν Λ֬ೝͨ͠Γ͢Δ • git

    checkout : ϒϥϯνΛ੾Γସ͑Δ • git merge : ϒϥϯνಉ࢜ΛϚʔδ͢Δ
  23. git pull • νʔϜ։ൃ͍ͯ͠Δ৔߹ʹɺϦϞʔτϦϙδτϦ͕
 ߋ৽͞ΕΔͷͰมߋΛऔΓࠐΉͨΊʹ git pull ίϚϯυͰ ϦϞʔτϦϙδτϦ͔ΒϩʔΧϧϦϙδτϦʹมߋΛ
 औΓࠐΉ࣌ʹ࢖༻͢Δ


    ˞ checkout ͢Δͱ͖͸ݱࡏͷϒϥϯνΛݩʹϒϥϯνΛ ࡞੒͢ΔͷͰ git pull Λͯ͠࠷৽ʹ͓ͯ͘͠ඞཁ͕͋Δ
 
 git pull origin master origin : ϦϞʔτϦϙδτϦͷผ໊
  24. GitHub Ͱͷ࣮ࡍͷ࡞ۀϑϩʔ master ϒϥϯν feature ϒϥϯνͳͲ ᶃ pull ͯ͠
 ࠷৽ʹ͢Δ

    ᶅ ίϛοτ͢Δ ᶆ GitHub ʹ
 push ͢Δ ᶄ checkout ͢Δ ᶇ Pull Request Λ౤͛Δ NBTUFSϒϥϯνΛ
 ࠷৽ʹͨ͠ঢ়ଶͰ
 NBTUFSϒϥϯν͔Β
 DIFDLPVU͠ͳ͍ͱ
 ݹ͍··ͳͷͰ஫ҙ
  25. ͜Ε·Ͱͷ·ͱΊ ͦͷ3 • git push : ϦϞʔτϦϙδτϦʹϓογϡ͢Δ • git pull

    : ϦϞʔτϦϙδτϦ͔ΒมߋΛऔಘ ͢Δ • git clone : ϦϞʔτϦϙδτϦ͔ΒϩʔΧϧʹ ϦϙδτϦΛऔಘ͢Δ
  26. ԋश • άϧʔϓΛ࡞Γ·͢ • νʔϜ಺ͷҰਓ͕ GitHub ্ʹϦϙδτϦΛ
 ࡞੒ͯ͠ɺΫϩʔϯ͠·͢ • Git

    ͷίϚϯυͷҙຯΛҰͭͣͭௐ΂·ͱΊͯɺ
 ίϛοτɺϓογϡ͠߹͍·͠ΐ͏
  27. ·ͱΊ • Git ͷ֓ཁ΍ Git Λ࢖ͬͨྲྀΕΛ཈͑ͨ • Git ͷίϚϯυʹ৮Εͨ •

    Git Λ࢖ͬͯखΛಈ͔ͯ͠Έͨ • ։ൃ͢Δ্Ͱ Git ͸σϑΝΫτελϯμʔυ
  28. ࢀߟจݙ • Git͕ɺ͓΋͠Ζ͍΄ͲΘ͔Δجຊͷ࢖͍ํ33 • https://ja.wikipedia.org/wiki/Git • https://git-scm.com/book/ja/v1/࢖͍࢝ΊΔ-࠷ॳͷGitͷߏ੒ • https://qiita.com/uasi/items/69368c17c79e99aaddbf •

    https://qiita.com/takeo-asai/items/9bc7e25cd94cd8c9adee • http://www-creators.com/archives/2106 • http://kimromi.hatenablog.jp/entry/2015/08/04/082357