Gitで始めるバージョン管理

070fe3c99a6af95b11cce4770ab772c1?s=47 arm4
September 21, 2018

 Gitで始めるバージョン管理

070fe3c99a6af95b11cce4770ab772c1?s=128

arm4

September 21, 2018
Tweet

Transcript

  1. GitͰ࢝ΊΔ όʔδϣϯ؅ཧ by Arm4

  2. ͜Ε͔Β࿩͢͜ͱ όʔδϣϯ؅ཧͬͯʁ gitͱ͸ʁ ϦϙδτϦͱ͸ʁ ϫʔΩϯάσΟϨΫτϦͱεςʔδϯά ΤϦΞ git؅ཧ͞ΕͨϑΝΠϧͷঢ়ଶ gitͷجຊతͳ࢖͍ํ ϒϥϯνʹ͍ͭͯ ଞͷΤϯδχΞͱ෼ࢄ࡞ۀ͠Α͏

  3. ຊ୊ͷલͷ஫ҙࣄ߲ ͋ͱͰΫΠζେձ͢ΔͷͰඞཁͳ͜ͱ͸ ϝϞΛऔΔΑ͏ʹʂ

  4. όʔδϣϯ؅ཧͬͯʁ

  5. ͜ͷલϦϦʔε ͨ͠๷ਓϘλϯ ͳΜ͚ͩͲɺ΋ ͏গ͠ΦγϟϨ UIʹ͢Δόʔ δϣϯ̎ͷ࿩͕ ܾ·ͬͨΑʂ PGͷϕϧࢠ SEͷN౻͞Μ

  6. όʔδϣϯ̎͸ ̏ϲ݄ޙͷϦϦʔ ε༧ఆͰɺͦͷ ؒʹόʔδϣϯ ̍ʹෆ۩߹͕ݟ ͔ͭͬͨΒɺόʔ δϣϯ̍ͷվम Λ͠ͳ͍ͱ͍͚ ͳ͍ΑͶ PGͷϕϧࢠ

    SEͷN౻͞Μ
  7. όʔδϣϯ̍ͷίʔυҰࣜΛ࢒ͯ͠ όʔδϣϯ̎ͷ։ൃΛਐΊΔʹ͸ Ͳ͏͢Ε͹͍͍͔ͳ͊ʁ /sakimori_1_release /sakimori_1_develop /sakimori_2_develop /sakimori_2_develop_nto /sakimori_2_2_develop /sakimori_2_2_20180613

  8. खಈόʔδϣϯ؅ཧ͕ ๊͍͑ͯͨ໰୊ όʔδϣϯ͕૿͍͑ͯ͘͝ͱʹɺͲΕ͕࠷৽ͰͲΕ͕ਖ਼͍͠ͷ͔ ൑ผͰ͖ͳ͘ͳ͍ͬͯ͘ɻ ୭͕Ͳ͜Λमਖ਼ͨ͠ͷ͔෼͔Βͳ͍ɻ όʔδϣϯຖͷίʔυͷࠩ෼ͷநग़͕༰қ͡Όͳ͍ɻ όοΫΞοϓΛऔΓ๨ΕΔͱޙ໭Γ͕Ͱ͖ͳ͍͕ɺࡉ͔͘όοΫ ΞοϓΛऔΓ͗͢ΔͱɺࠞཚΛট͘ɻ ಉ͡ϑΝΠϧΛಉ࣌ʹෳ਺ͷਓ͕मਖ਼͢Δ͜ͱ͕Ͱ͖ͳ͍ɻ ্ॻ͖͢Δͭ΋Γͷͳ͍ϑΝΠϧΛ্ॻ͖ͯ͠͠·͏ɻ

  9. ͜͏͍͏໰୊Λղܾͯ͘͠ΕΔΑ͏ͳ όʔδϣϯ؅ཧͷπʔϧ͕ ͋ͬͨΒ͍͍ͷʹͳ͊ ʊਓਓਓਓਓਓਓਓਓਓਓਓਓਓʊ ʼɹόʔδϣϯ؅ཧπʔϧര஀ɹʻ ʉY^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Yʉ

  10. ࠷ॳʹొ৔ͨ͠ όʔδϣϯ؅ཧγεςϜͷߏ଄ ͦΕͧΕͷ࡞ۀऀ͸ɺαʔ όʔʹ͋ΔதԝϦϙδτϦ ͔ΒιʔείʔυΛ࣋ͬͯ ͖ͯฤू͠ɺฤू͕ऴΘͬ ͨΒதԝϦϙδτϦʹ௚઀ ൓ө͢Δͱ͍͏ߏ଄ɻ ϦϙδτϦʹ͸มߋͷཤྺ ͕ه࿥͞ΕΔɻ

  11. ूதܕόʔδϣϯ؅ཧγεςϜ Subversion CVS Perforce

  12. ͜ΕͰ ಉ͡ϑΝΠϧͷιʔείʔυΛ ಉ࣌ʹमਖ਼Ͱ͖ΔΑ͏ʹͳͬͨ͠ όʔδϣϯ؅ཧ΋ ؆୯ʹͰ͖ΔΑ͏ʹͳͬͨʂ ͔͠͠ ूதܕόʔδϣϯ؅ཧγεςϜʹ΋ ໰୊఺͕͋ͬͨɾɾɾ

  13. ूதܕόʔδϣϯ؅ཧγεςϜͷ ໰୊఺ தԝϦϙδτϦͷ͋Δαʔό͕μ΢ϯ͢Δͱɺڞ ಉ࡞ۀ͕Ͱ͖ͳ͘ͳΔɻ ࡞ۀཤྺΛه࿥ͨ͠தԝϦϙδτϦ͕ো֐ͳͲͷ ཧ༝Ͱഁଛ͢Δͱɺࠓ·Ͱͷཤྺ͕ফࣦͯ͠͠· ͏ɻ αʔόʹ઀ଓͰ͖ͳ͍Α͏ͳωοτϫʔΫͷো֐ ͕͋Δͱ࡞ۀཤྺΛه࿥͢Δ͜ͱ͕Ͱ͖ͳ͍ɻ

  14. ͜ΕΒͷ໰୊Λղܾ͢Δ όʔδϣϯ؅ཧγεςϜ͕ ஀ੜ

  15. gitͱ͸ʁ

  16. ෼ࢄܕόʔδϣϯ؅ཧγεςϜ Git MercurialʢϚʔΩϡϦΞϧʣ Bazaarʢόβʔʣ

  17. ෼ࢄܕόʔδϣϯ؅ཧγεςϜͷ ߏ଄ ෼ࢄܕͰ͸ɺϩʔΧϧ؀ڥ ʢࣗ෼ͷPC౳ʣʹมߋཤ ྺΛؚΉ׬શͳϦϙδτϦ ͷෳ੡͕࡞੒͞ΕΔͱ͍͏ ࢓૊Έɻ ωοτϫʔΫʹ઀ଓ͍ͯ͠ ͳͯ͘΋ཤྺͷௐࠪ΍มߋ ͷه࿥Λߦ͏ࣄ͕ग़དྷΔɻ

  18. Git ։ൃऀ͸Linus TorvaldsʢϦʔφεɾτʔόϧζʣ Ϧʔφε͸LinuxΧʔωϧͷ։ൃऀͰ΋͋Δ LinuxΧʔωϧͷιʔείʔυ؅ཧʹ༻͍ΔͨΊ ʹ2005೥ʹ։ൃ͞Εͨ෼ࢄܕͷόʔδϣϯ؅ཧ γεςϜ

  19. ϦϙδτϦͱ͸ʁ

  20. repository ʲ໊ʳ 1. ऩೲʦอଘʧ৔ॴɺ૔ݿ 2. ത෺ؗɺඒज़ؗ 3. ஍Լຒ૴ॴɺ෿ุ 4. ʤ஌ࣝͳͲͷʥๅݿɺ๛෋ͳ஝͑


    ɾA griot in West Africa is a repository of oral tradition. : ੢ΞϑϦΧͷάϦΦ͸ޱ ಄఻ঝͷๅݿͰ͋Δɻ 5. ʤൿີΛଧͪ໌͚ΒΕΔʥ৴པͰ͖Δਓ
  21. ϦϙδτϦ ϓϩδΣΫτͷϑΝΠϧ΍σΟϨΫτϦͷ ঢ়ଶΛه࿥ͯ͠อ؅͓ͯ͘͠৔ॴ

  22. ̎छྨͷϦϙδτϦ ϦϞʔτϦϙδτϦ
 αʔόʹઃஔͯ͠ෳ਺ਓͰίʔυΛڞ༗͢Δͨ ΊͷϦϙδτϦ ϩʔΧϧϦϙδτϦ
 ֤ΤϯδχΞ͕ͦΕͧΕͷϩʔΧϧPC্Ͱ࢖͏ ϦϙδτϦ

  23. ϦϙδτϦʹ֨ೲ͢Δ΋ͷ ΞϓϦέʔγϣϯͷιʔείʔυ ΞϓϦέʔγϣϯʹ࢖༻͢Δը૾ ଞͷਓ͕ΞϓϦέʔγϣϯͷߏங ΍දࣔʹඞཁͳ΋ͷ

  24. ϦϙδτϦʹ֨ೲ͠ͳ͍΋ͷ ͦΕͧΕ͕Πϯετʔϧͯ͠࢖͏ Α͏ͳ֤छϥΠϒϥϦ ݸਓతͳΤσΟλͳͲͷઃఆϑΝ Πϧ Mac OSͰউखʹ࡞ΒΕΔΰϛϑΝ Πϧʢ.DS_Storeʣ Do Not

    Commit Please!!
  25. ϫʔΩϯάσΟϨΫτϦͱ εςʔδϯάΤϦΞ

  26. ϑΝΠϧͷঢ়ଶΛ؅ཧ͢Δ ̏ͭͷΤϦΞ ϫʔΩϯάσΟϨΫτϦ
 ʢ࡞ۀσΟϨΫτϦɺ࡞ۀπϦʔʣ
 ϦϙδτϦ͔ΒऔΓग़͞ΕͨҰͭͷಛఆͷόʔδϣϯͷϑΝΠϧ܈ εςʔδϯάΤϦΞ
 ʢΠϯσοΫεʣ
 ࣍ͷίϛοτʹؚ·͍ͤͨϑΝΠϧͷमਖ਼ཤྺͷ৘ใΛه࿥͓ͯ͘͠ ৔ॴ ϦϙδτϦ


    ʢGitσΟϨΫτϦʣ
 όʔδϣϯ͝ͱͷϑΝΠϧͷमਖ਼ཤྺΛอ؅͓ͯ͘͠৔ॴ
  27. ෺ཧతͳ৔ॴ /.git
 ~ /objects index
 ~ index.html /images /css /js

    ϫʔΩϯά
 σΟϨΫτϦ εςʔδϯά ΤϦΞ ϦϙδτϦ
  28. ϫʔΫϑϩʔ

  29. git؅ཧ͞ΕͨϑΝΠϧͷঢ়ଶ

  30. ະ௥੻ ( untracked ) มߋ͞Ε͍ͯͳ͍ ( unmodified ) มߋ͞Ε͍ͯΔ (

    modified ) εςʔδ͞Ε͍ͯΔ ( staged )
  31. gitͷجຊతͳ࢖͍ํ

  32. gitͷΠϯετʔϧ MacʹΠϯετʔϧ͢Δ৔߹ɺhomebrewͰΠϯε τʔϧ CentOSʹΠϯετʔϧ͢Δ৔߹ɺҎԼͷϖʔδ ͳͲΛࢀߟʹyumͰΠϯετʔϧ
 https://qiita.com/wslife/items/7572cdba2d60a00a3ffc

  33. ॳظઃఆ Ϣʔβ໊ɺE-mailΞυϨεɺΧϥʔͷઃఆ͸࠷௿ݶ͓ͯ͘͠
 http://blog.asial.co.jp/845 git config --global user.name "hoge" git config

    --global user.email hoge@example.co.jp git config --global color.ui auto git config --list git config
  34. ϔϧϓΛ֬ೝ͢Δ git help

  35. gitϦϙδτϦΛ࡞Δ(ϦϙδτϦͷॳظԽ) git init

  36. ϑΝΠϧͷঢ়ଶͷ֬ೝ git status

  37. ϑΝΠϧͷঢ়ଶΛදུ͢ه ?? = untracked ' ' = unmodified M =

    modified A = added D = deleted R = renamed C = copied U = updated but unmerged
  38. εςʔδϯάΤϦΞ΁ͷొ࿥ git add

  39. มߋΛϦϙδτϦʹه࿥͢Δ git commit

  40. ϑΝΠϧΛίϛοτ͠๨Εͨͱ͖ git commit −−amend

  41. ϑΝΠϧΛ࡟আ͠gitͷ௥੻͔Β֎͢ git rm ※gitʹ·ͩ௥੻͞Ε͍ͯͳ͍ϑΝΠϧ͸ɺ͜ͷίϚϯυͰ͸ ࡟আͰ͖ͳ͍ɻ ※มߋ͕εςʔδ͞Ε͍ͯΔϑΝΠϧ͸ɺ-f ΦϓγϣϯͰڧ ੍తʹ࡟আ͠ͳ͚Ε͹ͳΒͳ͍ɻ

  42. ϑΝΠϧΛ࢒͠gitͷ௥੻͔Β֎͢ git rm −−cached

  43. ίϛοτཤྺΛ֬ೝ͢Δ git log

  44. ศརͳlogͷΦϓγϣϯ git log -p
 diffΛՃ͑ͨίϛοτϩάʢύονΛදࣔʣ git log -2
 දࣔ͢Δίϛοτϩάͷ਺Λࢦఆ git

    log --stat
 มߋ͞ΕͨϑΝΠϧΛදࣔ(౷ܭ৘ใɺεςʔλεΛදࣔ) git log --pretty=oneline
 ίϛοτϩάΛ̍ߦͰදࣔ git log --pretty=format:"%h - %an, %ar : %s"
 ϋογϡ - ίϛοτͨ͠ਓͷ໊લ, ૬ର೔෇ : ໊݅
  45. git log --graph
 ϒϥϯνͷϚʔδཤྺΛΞεΩʔάϥϑͰදࣔͯ͘͠ΕΔ git log --since=2weeks
 git log --since=2018-06-07


    ͍͔ͭΒͰҾֻ͚ͬΔ git log --until=2weeks
 ͍ͭ·ͰͰҾֻ͚ͬΔ git log --author=beruko
 ίϛοτͨ͠ਓͰҾֻ͚ͬΔ git log --grep=ސ٬
 ໊݅ͰҾֻ͚ͬΔ git log database/seeds/MenuSeeder.php
 มߋͷ͋ͬͨϑΝΠϧͷύεͰҾֻ͚ͬΔ git log --pretty="%h %an -%s" --author=nto --since="2018-05-01" -- until="2018-05-31"
 2018೥5݄ʹnto͞Μͷίϛοτͨ͠ཤྺͷΈΛදࣔ
  46. ࠩ෼Λ֬ೝ͢Δ git diff

  47. ༷ʑͳdiffΛදࣔ͢Δ git diff
 ݱࡏͷϫʔΫσΟϨΫτϦͱεςʔδϯάΤϦΞͱͷࠩ෼Λදࣔ git diff --cached
 git diff --staged


    εςʔδϯάΤϦΞͱ࠷৽ͷίϛοτ(HEAD)ͱͷࠩ෼Λදࣔ git diff HEAD
 ݱࡏͷϫʔΫσΟϨΫτϦͱ࠷৽ͷίϛοτ(HEAD)ͷࠩ෼Λදࣔ͢Δ git diff HEAD^
 git diff HEAD^..HEAD
 ࠷৽ͷίϛοτͱ࠷৽ͷίϛοτͷͻͱͭલͱͷࠩ෼Λදࣔ͢Δ git diff <ίϛοτϋογϡ>
 ݱࡏͷϫʔΫσΟϨΫτϦͱಛఆͷίϛοτͱͷࠩ෼Λදࣔ
  48. git diff <ίϛοτϋογϡ>..<ίϛοτϋογϡ>
 ίϛοτಉ࢜Λൺֱͨࠩ͠෼Λදࣔ git diff <ϒϥϯν໊>..<ϒϥϯν໊>
 ϒϥϯνಉ࢜ͷࠩ෼Λදࣔ git diff

    -- <ϑΝΠϧͷύε>
 ಛఆͷύεͷΈͷdiffΛදࣔɻύεͷΈࢦఆ͢Δ৔߹͸--͸লུ Մೳ git diff <ϒϥϯν໊>..<ϒϥϯν໊> -- <ϑΝΠϧͷύε>
 ಛఆͷϑΝΠϧΛผͷϒϥϯνͱൺֱͨࠩ͠෼Λදࣔ git diff --word-diff
 ࠩ෼ΛจࣈϨϕϧͰൺֱ͢Δ git diff --diff-filter=M
 मਖ਼ͨ͠ϑΝΠϧͷdiffͷΈΛදࣔ͢ΔΦϓγϣϯ
  49. εςʔδͨ͠ϑΝΠϧͷऔΓফ͠ git reset ※git reset͸ΦϓγϣϯΛ͚࣮ͭͯߦ͢ΔͱେมةݥͳίϚϯ υͳͷͰؒҧ͑ͯΦϓγϣϯΛ͚ͭͳ͍Α͏ʹ஫ҙʂ

  50. ϫʔΩϯάσΟϨΫτϦͷ มߋΛऔΓফ͢ git checkout -- .