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

Git.pdf

AkitoTameto
October 24, 2019
75

 Git.pdf

AkitoTameto

October 24, 2019
Tweet

Transcript

  1. ࣗݾ঺հ • ໊લɹɿ ஑ా ༗ًকʢϢΩϚαɺϢΩʣ • ॴଐɹɿ גࣜձࣾϛϥΠτσβΠϯ • ݴޠɹɿ

    Ruby (Rails) / iOSʢswiftʣ/ Androidʢjavaʣ • ࣮຿ɹɿ 6ϲ݄໨ • લ৬ɹɿ ધഫ৐ધһʢλάϘʔτʣ • ग़਎ɹɿ ਆಸ઒ݝԣ඿ࢢ • Twitterɿ @yyykms123
  2. ࣗݾ঺հ • ໊લɹɿ ҝ౻ ΞΩτ • ॴଐɹɿ גࣜձࣾϛϥΠτσβΠϯ • ݴޠɹɿ

    Ruby (Rails) / iOSʢswiftʣ/ Androidʢjavaʣ • ࣮຿ɹɿ 6ϲ݄໨ • લ৬ɹɿ αϙʔτσεΫ • ग़਎ɹɿ ઍ༿ݝחέ୩ࢢ • Twitterɿ @akito_tameto • झຯ ɿ ےτϨ͕޷͖Ͱ͢ὑ
  3. 1. ࣮຿ͰΑ͘࢖͏ίϚϯυ 7. git diff 8. git add 9. git

    commit 10. git log 11. git push 12. git reset 1. git pull 2. git fetch 3. git merge 4. git checkout 5. git branch 6. git status
  4. ·ͣ͸ɺͪ͜Βͷ3ͭʂʂ 7. git diff 8. git add 9. git commit

    10. git log 11. git push 12. git reset 1. git pull 2. git fetch 3. git merge 4. git checkout 5. git branch 6. git status
  5. ࣍͸ɺͪ͜Βʂʂ 7. git diff 8. git add 9. git commit

    10. git log 11. git push 12. git reset 1. git pull 2. git fetch 3. git merge 4. git checkout 5. git branch 6. git status
  6. git branch • ϒϥϯνͷҰཡΛ֬ೝͰ͖Δ $ $ git branch -D ࡟আ͢Δϒϥϯν໊

    • ݱࡏͲͷϒϥϯν͔Λ֬ೝͰ͖Δ • Φϓγϣϯ-DͰϒϥϯνΛ࡟আͰ͖Δ
  7. ࣍͸ɺͪ͜Βʂʂ 7. git diff 8. git add 9. git commit

    10. git log 11. git push 12. git reset 1. git pull 2. git fetch 3. git merge 4. git checkout 5. git branch 6. git status
  8. ࣍͸ɺͪ͜Βʂʂ 7. git diff 8. git add 9. git commit

    10. git log 11. git push 12. git reset 1. git pull 2. git fetch 3. git merge 4. git checkout 5. git branch 6. git status
  9. git add • मਖ਼ɺ௥Ճͨ͠ϑΝΠϧΛεςʔδϯάΤϦΞ΁ ௥ՃͰ͖Δ $ $ git add .

    • ΦϓγϣϯͰ.(υοτ)Λར༻͢ΔͱશͯΛબ୒Ͱ͖Δ • ϑΝΠϧΛࢦఆ͢Δࣄ΋Ͱ͖Δ • ଞͷΦϓγϣϯ͸͓·͚Ͱ঺հ͠·͢ὑ
  10. git commit • ϦϙδτϦʹ൓ө͢Δʹ͸ొ࿥(ه࿥)Λ͠·͢ $ $ git commit -m ‘ίϛοτϝοηʔδ’

    • Φϓγϣϯ-mͰvimͳͲΛ։͔ͣʹίϛοτϝοηʔδΛ ೖྗͰ͖·͢
  11. ࣍͸ɺͪ͜Βʂʂ 7. git diff 8. git add 9. git commit

    10. git log 11. git push 12. git reset 1. git pull 2. git fetch 3. git merge 4. git checkout 5. git branch 6. git status
  12. ࣍͸ɺͪ͜Βʂʂ 7. git diff 8. git add 9. git commit

    10. git log 11. git push 12. git reset 1. git pull 2. git fetch 3. git merge 4. git checkout 5. git branch 6. git status
  13. ࠷ޙʹͪ͜Βʂʂ 7. git diff 8. git add 9. git commit

    10. git log 11. git push 12. git reset 1. git pull 2. git fetch 3. git merge 4. git checkout 5. git branch 6. git status
  14. rebase UPQJD NBTUFS $ $ git checkout topic $ $

    git rebase master UPQJD NBTUFS
  15. rebase UPQJD NBTUFS $ $ git checkout master $ $

    git merge topic $ NBTUFS UPQJD NBTUFS fast forward
  16. rebase UPQJD NBTUFS $ $ git checkout master $ $

    git merge topic $ NBTUFS NBTUFS UPQJD NFSHFίϛοτ non fast forward
  17. ίϯϑϦΫτ $ $ git rebase master topic First, rewinding head

    to replay your work on top of it... Applying: new topic Using index info to reconstruct a base tree... M test.txt Falling back to patching base and 3-way merge... Auto-merging test.txt CONFLICT (content): Merge conflict in test.txt error: Failed to merge in the changes. Patch failed at 0001 new topic hint: Use 'git am --show-current-patch' to see the failed patch Resolve all conflicts manually, mark them as resolved with "git add/rm <conflicted_files>", then run "git rebase --continue". You can instead skip this commit: run "git rebase --skip". To abort and get back to the state before "git rebase", run "git rebase --abort".
  18. 3ͭͷબ୒ࢶ • git rebase --continue ίϯϑϦΫτΛղফ͔ͯ͠Βଓ͚Δ৔߹ • git rebase --skip

    ίϛοτΛඈ͹͢৔߹ • git rebase --abort rebaseΛதஅ͢Δ৔߹
  19. git rebase -i <commit> $ git log --oneline f65ceba E

    46c578f C dadaaee D abeb89d B 4dd6e33 A $ ίϛοτCͱDͷॱ൪ΛೖΕସ͍͑ͨʂʂ
  20. git rebase -i <commit> $ git log --oneline f65ceba E

    46c578f C dadaaee D abeb89d B 4dd6e33 A $ ίϛοτCͱDͷॱ൪ΛೖΕସ͍͑ͨʂʂ git rebase -i HEAD~3
  21. git rebase -i <commit> pick f65ceba E # Rebase abeb89d..f65ceba

    onto abeb89d (3 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec <command> = run command (the rest of the line) using shell ..ҎԼলུ.. pick dadaaee D pick 46c578f C ίϛοτCͱDͷॱ൪ΛೖΕସ͍͑ͨʂʂ
  22. git rebase -i <commit> pick f65ceba E # Rebase abeb89d..f65ceba

    onto abeb89d (3 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec <command> = run command (the rest of the line) using shell ..ҎԼলུ.. pick 46c578f C pick dadaaee D ೖΕସ͑Δ ίϛοτCͱDͷॱ൪ΛೖΕସ͍͑ͨʂʂ
  23. git rebase -i <commit> ίϛοτCͱDͷॱ൪ΛೖΕସ͍͑ͨʂʂ $ git rebase -i HEAD~3

    Auto-merging sample.txt CONFLICT (content): Merge conflict in sample.txt error: could not apply 46c578f... C Resolve all conflicts manually, mark them as resolved with "git add/rm <conflicted_files>", then run "git rebase --continue". You can instead skip this commit: run "git rebase --skip". To abort and get back to the state before "git rebase", run "git rebase --abort". Could not apply 46c578f... C ίϯϑϦΫτΛղফ͢Δʂʂ ↓ git add sample.txt ↓ git rebase --continue
  24. git rebase -i <commit> ίϛοτCͱDͷॱ൪ΛೖΕସ͍͑ͨʂʂ $ git log --oneline 4bfc0bf

    E e1fc7e4 D e319908 C abeb89d B 4dd6e33 A $ ॱ൪ͱίϛοτID͕มΘ͍ͬͯΔ
  25. git rebase -i <commit> $ git log --oneline 4bfc0bf E

    e1fc7e4 D e319908 C abeb89d B 4dd6e33 A $ ίϛοτBͱCͱDΛ·ͱΊ͍ͨʂʂ git rebase -i HEAD~4
  26. git rebase -i <commit> ίϛοτBͱCͱDΛ·ͱΊ͍ͨʂʂ pick abeb89d B pick 4bfc0bf

    E # Rebase 4dd6e33..4bfc0bf onto 4bfc0bf (4 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message ..ҎԼলུ.. pick e319908 C pick e1fc7e4 D
  27. git rebase -i <commit> ίϛοτBͱCͱDΛ·ͱΊ͍ͨʂʂ pick abeb89d B pick 4bfc0bf

    E # Rebase 4dd6e33..4bfc0bf onto 4bfc0bf (4 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message ..ҎԼলུ.. s e319908 C s e1fc7e4 D ίϛοτΛ1ͭલͷίϛοτʹ౷߹
  28. git rebase -i <commit> ίϛοτBͱCͱDΛ·ͱΊ͍ͨʂʂ # This is a combination

    of 3 commits. # This is the 1st commit message: # This is the commit message #2: # This is the commit message #3: # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # ..ҎԼলུ.. B C D
  29. git rebase -i <commit> ίϛοτBͱCͱDΛ·ͱΊ͍ͨʂʂ # This is a combination

    of 3 commits. # This is the 1st commit message: # This is the commit message #2: # This is the commit message #3: # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # ..ҎԼলུ.. B+C+D
  30. git rebase -i <commit> $ git log --oneline 4bfc0bf E

    3ba9c8d B+C+D 4dd6e33 A $ ίϛοτϝοηʔδΛมߋ͍ͨ͠ʂʂ
  31. git rebase -i <commit> $ git log --oneline 4bfc0bf E

    3ba9c8d B+C+D 4dd6e33 A $ ίϛοτϝοηʔδΛมߋ͍ͨ͠ʂʂ git commit --amend $ git log --oneline 4bfc0bf C 3ba9c8d B+C+D 4dd6e33 A $ 1ͭલͷίϛοτϝοηʔδ͸ git commit --amend ͰมߋͰ͖Δɻ ίϛοτϝοηʔδΛ ʮEʯ͔ΒʮCʯʹมߋɻ
  32. git rebase -i <commit> $ git log --oneline 4bfc0bf E

    3ba9c8d B+C+D 4dd6e33 A $ ίϛοτϝοηʔδΛมߋ͍ͨ͠ʂʂ git commit --amend $ git log --oneline 4bfc0bf C 3ba9c8d B+C+D 4dd6e33 A $ git rebase -i HEAD~2 2ͭҎ্લͷίϛοτϝοηʔδ͸ git rebase -i ͰมߋͰ͖Δɻ
  33. git rebase -i <commit> ίϛοτϝοηʔδΛมߋ͍ͨ͠ʂʂ pick 94dbe7b E # Rebase

    4dd6e33..94dbe7b onto 4dd6e33 (2 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message ..ҎԼলུ.. pick 3ba9c8d B+C+D
  34. git rebase -i <commit> ίϛοτϝοηʔδΛมߋ͍ͨ͠ʂʂ pick 94dbe7b E # Rebase

    4dd6e33..94dbe7b onto 4dd6e33 (2 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message ..ҎԼলུ.. e 3ba9c8d B+C+D
  35. git rebase -i <commit> ίϛοτϝοηʔδΛมߋ͍ͨ͠ʂʂ $ git rebase -i HEAD~2

    Stopped at 3ba9c8d... B+C+D You can amend the commit now, with git commit --amend Once you are satisfied with your changes, run git rebase --continue $
  36. git rebase -i <commit> ίϛοτϝοηʔδΛมߋ͍ͨ͠ʂʂ $ git rebase -i HEAD~2

    Stopped at 3ba9c8d... B+C+D You can amend the commit now, with git commit --amend Once you are satisfied with your changes, run git rebase --continue $ git commit --amend [detached HEAD 3c3629a] B Date: Sat Oct 19 14:20:11 2019 +0900 1 file changed, 3 insertions(+) $ git rebase --continue Successfully rebased and updated refs/heads/master. --amendͰίϛοτϝοηʔδΛ ʮB+C+Dʯ͔ΒʮBʯʹมߋ
  37. git rebase -i <commit> ίϛοτϝοηʔδΛมߋ͍ͨ͠ʂʂ $ git log --oneline 4bfc0bf

    C 3ba9c8d B 4dd6e33 A $ edit͸ίϛοτϝοηʔδͷมߋ͚ͩͰͳ͘ɺ ϑΝΠϧͷมߋ౳΋Մೳʂʂ
  38. ϦΫΤετ ޮՌ p, pick ίϛοτΛ࢖༻͢Δ r, reword ίϛοτϝοηʔδΛฤू e, edit

    ίϛοτ಺༰Λमਖ਼͢Δ s, squash มߋ಺༰Λ௚લͷίϛοτʹ౷߹ f, fixup มߋ಺༰Λ௚લͷίϛοτʹ౷߹ ίϛοτϝοηʔδΛഁغ x, exec γΣϧίϚϯυΛ࣮ߦ d, drop ίϛοτΛ࡟আ
  39. git add ͷओͳΦϓγϣϯ Φϓγϣϯ ҙຯ -A (-all) มߋ/৽ن/࡟আͨ͠ϑΝΠϧΛadd͢Δ . (υοτ)

    มߋ/৽ن/࡟আͨ͠ϑΝΠϧΛadd͢Δ -u (--update) มߋ/࡟আͨ͠ϑΝΠϧΛadd͢Δ -i (--interactive) ର࿩తʹϑΝΠϧΛadd͢Δ
  40. configʹΤΠϦΞεΛઃఆ͢Δ • git status ͱଧͨͳͯ͘΋ git st Ͱ࣮ߦͰ͖Δ • ϦϙδτϦ୯ҐͰઃఆ͢ΔͳΒ

    --local ͱ͢Δ • git config --global -e ͱ͢ΔͱΤσΟλ͕։͘ͷ Ͱɺ௚઀هड़͢Δ͜ͱ΋Ͱ͖Δ $ git config --global alias.st status
  41. ΤΠϦΞεͷઃఆྫ [alias] st = status sts = status --short --branch

    cm = commit co = checkout br = branch df = diff lg = log --oneline --graph -10 ss = stash