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

Git Bootcamp

Git Bootcamp

2017年4~5月開催「ブートキャンプ特別講座」の資料になります。

Recruit Technologies

June 02, 2017
Tweet

More Decks by Recruit Technologies

Other Decks in Technology

Transcript

  1. Git Bootcamp • ΧϦΩϡϥϜ • Git-it Ͱ Git ͷ࢖͍ํΛମܥతʹֶͿ •

    Git Tips ू • ͜Μͳ࣌Ͳ͏͢Δʁ Git ԋशฤ • ࣮ࡍʹGitHubͰNode.jsʹίϯτϦϏϡʔτͯ͠ΈΔ
  2. Git it Λ࣮ߦ͢Δ • Լهͷͱ͜Ζ͔Βμ΢ϯϩʔυ࣮ͯ͠ߦ • https://github.com/jlord/git-it-electron/releases • ΞϓϦέʔγϣϯϑΥϧμͷԼʹgit-itΛ഑ஔ্ͨ͠Ͱ ࣮ߦ͍ͯͩ͘͠͞

    • securityͷΤϥʔ͕ग़ͨΒઃఆ>ηΩϡϦςΟͱϓϥΠ όγ>μ΢ϯϩʔυͨ͠ΞϓϦέʔγϣϯͷ࣮ߦڐՄ> ͢΂ͯͷΞϓϦέʔγϣϯΛڐՄʢ͋ͱͰ໭ͯ͠Ͷʣ
  3. Git it Λ࣮ߦ͢Δ • େମ1࣌ؒ͘Β͍Λ໨҆ʹશ෦ճ౴͍ͯͩ͘͠͞ɻ • git ͷίϚϯυʹ৮Εͭͭ΋͜ͷػձʹGitHubͷ ΞΧ΢ϯτ͕ͳ͍ਓ͸࡞͓͖ͬͯ·͠ΐ͏ɻ •

    ૣ͍ਓͰ1࣌ؒ͘Β͍ɺ஗ͯ͘΋2࣌ؒ͘Β͍Ͱऴ ΘΔҹ৅Ͱ͕͢ɺऴΘΓํ࣍ୈͰ࣍ͷΧϦΩϡϥ ϜΛܾΊ·͢ɻ
  4. Gitখ࢙ $ git log e83c516 commit e83c5163316f89bfbde7d9ab23ca2e25604af290 Author: Linus Torvalds

    <[email protected]> Date: Thu Apr 7 15:13:13 2005 -0700 Initial revision of "git", the information manager from hell
  5. Gitখ࿩ • gitͷMLͰɺͳͥgitͰC++Λ࢖Θͳ͍ͷ͔ͱ͍ ͏࣭໰ʹରͯ͠ɺLinusͷճ౴ > > GitͷιʔείʔυΛ࢝ΊͯΈͨ࣌ɺ2ͭͷ͜ͱ͕಄ʹͻ͔͔ͬͬͨɻ > 1. C++͡Όͳͯ͘७ਮͳCɻཧ༝͸ෆ໌ɻҠ২ੑͱ͔ݴΘͳ͍ͰΑɻ

    > Ϋιͩɻ Ϋι·ΈΕͳͷ͸Φϝʔͷํͩɻ C++͸൵ࢂͳݴޠͩɻ͔͠΋ɺগͳ͔Β͵਺ͷϓϩάϥϚʔ͕࢖͍ͬͯͯɺ׬શແܽͷͲ͏͠Α͏΋ͳ͍Ϋι Λੜ੒͢Δͷ͕ΊͪΌΊͪΌ؆୯ʹͳ͍ͬͯΔͱ͍͏఺ͰɺΑ͚͍ʹ൵ࢂͩɻϚδͰɺCΛબ୒͢Δཧ༝͕ ʮԿ΋ͳ͔ͬͨʯͱͯ͠΋ͩɺC++ϓϩάϥϚʔආ͚ʹͳΔͱ͍͏͚ͩͰɺCΛ࢖͏େ໊ٛ෼ʹͳΔɻ
  6. Git Tips ͦͷ2: git hook • git Ͱίϛοτ࣌΍push࣌ʹίϚϯυΛ࣮ߦ ͢Δπʔϧ •

    node.jsϓϩδΣΫτͰ͸husky͍ͬͯ͏πʔ ϧ͕͋ͬͯͦΕΛ࢖ͬͯhookͤ͞Δ͜ͱ͕ଟ ͍
  7. ͏͔ͬΓؒҧͬͯadd/commit ͨ͠ͱ͖ # git reset Λ࢖͍·͠ΐ͏ $ git reset --soft

    HEAD^ // ҰݸલͷίϛοτΛऔফ͠ $ git reset --soft HEAD^^ // ೋݸલͷίϛοτΛऔΓফ͢ # ͪͳΈʹ tig Ͱ΍Δͱ add ͷ৔߹͸΋ͬͱ؆୯ $ tig status
  8. ͏͔ͬΓؒҧͬͯpushͨ͠ͱ͖ # ·ͣɺνʔϜ։ൃத͸ master ΁ͷ௚push͸ۃྗආ͚Δ (Pull RequestϕʔεͰશһ͕؂ ࢹͰ͖ΔΑ͏ʹ͠ͳ͕Β։ൃ͢Δʣ # masterҎ֎ͷϒϥϯνʢࣗ෼ͷϒϥϯνͳΒpushͯ͠΋औΓฦ͕ͭ͘͠ʣ

    # master ͷ৔߹ɺͦͷλΠϛϯάͰclone͞ΕͨΓpull͞ΕͨΓ͢Δͱඇৗʹ໘౗ͳ͜ͱʹ ͳΔ $ git rebase -i Ͱpushͯ͠͠·ͬͨίϛοτΛऔΓফ͢ $ ͜ͷ git rebase ͕ΊͬͪΌ࢖͏ $ git rebase -i ͢ΔͱΤσΟλ͕։͘ͷͰɺͦͷΤσΟλ্Ͱ֘౰ίϛοτΛ࡟আ $ ࡟আͨ͠Β git push -f Ͱforce push $ master ΁ͷ force push ͸ݫېͳ͕࣌͋ΔͷͰඇৗʹؾΛ͚ͭΔ
  9. ͏͔ͬΓؒҧͬͯmaster merge ͨ͠ͱ͖ # جຊ͸ revert ͢Δ # master ʹpush͞Εͨ΋ͷΛ҆શʹऔΓফ͢ͷ͸revertͰ΍Δͷ͕ྑ͍

    # ͨͩ͠ɺrevert͢Δͱrevert commit(औΓফͨ͢Ίͷcommit͕ͭ͘) # git ͷຊདྷతͳ࢖͍ํͱͯ͠͸revert͕ਖ਼͍͠ $ git revert HEAD~2 (ೋݸલͷίϛοτΛrevert)
  10. ίϛοτͨ͋͠ͱͰtypo͕͋ͬͯ typoͨ͠Βtypo͕typoͯͨ͠ # git log fix: typo fix: typo feat:

    Add new feature Έ͍ͨͳͱ͖ # git rebase -i HEAD~{3} ͔ͯ͠Β औΓࠐΈ͍ͨ΍ͭͱऔΓࠐΈͨ͘ͳ͍΍ͭΛ෼͚ͯϚʔδ͢Δ
  11. ίϛοτͨ͋͠ͱͰtypo͕͋ͬͯ typoͨ͠Βtypo͕typoͯͨ͠ ίϛοτϝοηʔδΛ fixup ͱ͔ squash ʹ͓ͯ͘͠ͱ git rebase -i

    --autosquash Ͱϋο ϐʔʹͳΔ git commit --fixup <COMMIT ID> Ͱ΋ྑ͍ ※ autosquashΛ࢖͏࣌͸௚લͷίϛοτͷϝοηʔδͷઌ಄਺จࣈؚ͕·Ε͍ͯΔඞཁ͕ ͋Δɻ
  12. passwordΛ͏͔ͬΓೖΕͪΌͬͨͷ Ͱաڈͷίϛοτ͔Βશͯ࡟আ͍ͨ͠ # git filter-branch ͷ commit-filter Λ࢖͏ $ git

    filter-branch -f --commit-filter 'if [ "$GIT_AUTHOR_EMAIL" = "[email protected]" ]; then GIT_AUTHOR_NAME="Yochan"; GIT_AUTHOR_EMAIL="[email protected]"; git commit-tree "$@"; else git commit-tree "$@"; fi' HEAD
  13. SVN͔ΒGitʹӡ༻ม͍͑ͨΜ ͚ͩͲɻ • SVN => தԝूݖܕ • Git => ෼ࢄܕ

    • Ұ൪͍͍ͷ͸Github͕ࠓ΍σϑΝΫτελϯμʔυͳͷ ͰɺͦΕҎ֎Ͱ΍ΔͳΒ߱ΓΔͧͬͯڴͯ͠΋ՄɻͦΕ Ͱฆڄͨ͠Β๻ΛݺΜͰ͍ͩ͘͞ɻ • see: http://qiita.com/YusukeHosonuma/items/ 14c59f3878d640a401a1
  14. git reflog ࠷ѱϩʔΧϧ͕ফ͑ͨΓϒϥϯν͕ফ͑ͨΓͨ࣌͠ͷ࠷ऴखஈ $ git reset --hard HEAD^^ # HEAD^ͱࢦఆ͢Δͭ΋Γ͕ؒҧ͑ͨ!

    $ git reflog f5cb888 HEAD@{0}: head^^: updating HEAD 05b76fe HEAD@{1}: commit: 2.6.2 a546c2c HEAD@{2}: pull origin master: Fast-forward 843a591 HEAD@{3}: commit: rename package.json authors 6c66867 HEAD@{4}: pull origin master: Fast-forward 3e15c9e HEAD@{5}: checkout: moving from add_recruit_tech_problems to master 4af78a2 HEAD@{5}: commit: feat: add scope $ git reset --hard HEAD@{1} # reset hard લʹ໭ΕΔ
  15. git bisect Ͳ͔͜Β͔ɺੑೳ͕མͪͨɾςετ͕failʹͳͬͨ౳ͷ৔߹ͰͲ͜ͷίϛοτͰͦͷݱ৅͕ى ͖ͨͷ͔Λಛఆ͢ΔͨΊͷํ๏ɺೋ෼୳ࡧͰݕࡧͯ͘͠ΕΔ $ git bisect start HEAD v2.0

    # v2.0Ͱ͸େৎ෉͚ͩͬͨͲHEADͰ͸໰୊͕͋Δ $ git bisect run <ςετίϚϯυ> # ͜ΕͰࣗಈతʹςετ͠ͳ͕Βfail/successͰίϛοτΛݟ͚ͭͯ͘ΕΔ $ git bisect good $ git bisect bad # खಈͰςετ͢ΔͳΒ͜ͷ΍Γํ͕͋Δ