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

これからはじめるGit

 これからはじめるGit

広島フロントエンド勉強会 Vol.29の発表資料

井上拓

May 25, 2022
Tweet

More Decks by 井上拓

Other Decks in Technology

Transcript

  1. pull commit merge checkout branch stash push add diff status

    log reset revert rebase rm stash commit diff merge log add checkout pull push commit ޿ౡϑϩϯτΤϯυษڧձ7PM ʰ͜Ε͔Β͸͡ΊΔ(JUʱ
  2. GitͷϝϦοτ • มߋͷཤྺ • ࠩ෼ͷൺֱ • ཤྺ͔Βͷ෮ݩ • ෳ਺ͷมߋΛ౷߹ ఏҊॻΛ࡞੒

    ϓϥϯ1Λ௥Ճ ϓϥϯ1ͷݟੵ΋ΓΛ௥Ճ ϓϥϯ2Λ௥Ճ ϓϥϯ1Λमਖ਼ ϓϥϯ2ͷݟੵ΋ΓΛ௥Ճ ϓϥϯ1ͷݟੵ΋ΓΛमਖ਼ 2022.05.21 15:25 2022.05.20 22:46 2022.05.20 20:10 2022.05.19 10:43 2022.05.19 16:08 2022.05.18 19:27 2022.05.18 10:00 Ҫ্ ࡔຊ Ҫ্ ࡔຊ Ҫ্ Ҫ্ Ҫ্
  3. $ git con fi g --global user.name "XXXX" • Ϣʔβʔ໊Λઃఆ͢Δ

    • ୭͕ίϛοτͨ͠΋ͷ͔Θ͔ΔΑ͏ʹ $ git con fi g --global user.email "[email protected]" • ϝʔϧΞυϨεΛઃఆ͢Δ • SaaSͰ͸ϝʔϧΞυϨεʹඥ͍ͮͯΞΠίϯͳͲ͕දࣔ͞ΕΔ
  4. index.htmlΛ࡞੒͠·͢ <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link rel="stylesheet"

    href=""> <title>index</title> </head> <body> </body> </html> JOEFYIUNM
  5. $ git status • ϫʔΩϯάπϦʔʹ͋ΔϑΝΠϧͷঢ়ଶΛදࣔ͢Δ On branch main No commits

    yet Changes to be committed: (use "git rm --cached < fi le>..." to unstage) new fi le: index.html
  6. On branch main No commits yet Changes to be committed:

    (use "git rm --cached < fi le>..." to unstage) new fi le: index.html Untracked fi les: (use "git add < fi le>..." to include in what will be committed) index2.html addͯ͠ͳ͍ϑΝΠϧ͕͋Δ৔߹
  7. ʲ͜͜ʹϝοηʔδΛॻ͘ʳ # Please enter the commit message for your changes.

    Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch main # # Initial commit # # Changes to be committed: # new fi le: index.html ίϛοτϝοηʔδΛೖྗ͢Δը໘͕։͘ viͷૢ࡞͕ඞཁɻΠϯαʔτϞʔυ͸ʮiʯɺίϚϯυϞʔυ͸ʮescʯɺอଘ͸ίϚϯυϞʔυͰʮ:wqʯɺอଘͤͣด͡Δ৔߹͸ʮ:q!ʯ
  8. index.htmlʹh1Λ௥Ճ <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link rel="stylesheet"

    href=""> <title>index</title> </head> <body> <h1>index</h1> </body> </html> JOEFYIUNM
  9. $ git log $ git log commit 6156b13a243e2121ef0f054316915795b22e5ded (HEAD ->

    main) Author: XXXX <[email protected]> Date: Sun May 15 00:15:34 2022 +0900 h2Λ௥Ճ commit 6f0165b3aa719d4ede12ade9d61e3b491d0c795d Author: XXXX <[email protected]> Date: Sun May 15 00:00:24 2022 +0900 “index.htmlΛ௥Ճ”
  10. $ git commit --amend • ௚લͷίϛοτΛमਖ਼͢Δ • git commitͱಉ͡Α͏ͳը໘͕։͘ h2Λ௥Ճ

    # Date: Fri May 13 23:13:05 2022 # # On branch main # Changes to be committed: # modi fi ed: index.html h1Λ௥Ճ # Date: Fri May 13 23:13:05 2022 # # On branch main # Changes to be committed: # modi fi ed: index.html
  11. $ git log $ git log commit 6156b13a243e2121ef0f054316915795b22e5ded (HEAD ->

    main) Author: XXXX <[email protected]> Date: Sun May 15 00:15:34 2022 +0900 h1Λ௥Ճ commit 6f0165b3aa719d4ede12ade9d61e3b491d0c795d Author: XXXX <[email protected]> Date: Sun May 15 00:00:24 2022 +0900 “index.htmlΛ௥Ճ”
  12. index2.htmlʹ௥ه <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link rel="stylesheet"

    href=""> <title>index3</title> </head> <body> <h1>index3</h1> </body> </html> JOEFYIUNM
  13. $ git reset • ΠϯσοΫε͔Βશͯ࡟আ͢Δ • ϫʔΩϯάπϦʔ͸ӨڹΛड͚ͳ͍(มߋ͸ফ͑ͳ͍) $ git reset

    index3.html • ಛఆͷϑΝΠϧΛΠϯσοΫε͔Β࡟আ͢Δ $ git reset --mixed HEAD
  14. $ git log $ git log commit 6156b13a243e2121ef0f054316915795b22e5ded (HEAD ->

    main) Author: XXXX <[email protected]> Date: Sun May 15 00:15:34 2022 +0900 index2.htmlʹ௥ه commit 6f0165b3aa719d4ede12ade9d61e3b491d0c795d Author: XXXX <[email protected]> Date: Sun May 15 00:00:24 2022 +0900 index3.htmlΛ௥Ճ
  15. ࠶౓index2.htmlʹ௥ه <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link rel="stylesheet"

    href=""> <title>index2</title> </head> <body> <h1>index2</h1> </body> </html> JOEFYIUNM
  16. index.htmlʹpΛ௥Ճ <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link rel="stylesheet"

    href=""> <title>index</title> </head> <body> <h1>index</h1> <p>Hello index</p> </body> </html> JOEFYIUNM
  17. index.htmlΛݟͯΈΔͱ devͰߦͬͨมߋ͕దԠ͞Ε͍ͯΔ <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link

    rel="stylesheet" href=""> <title>index</title> </head> <body> <h1>index</h1> <p>Hello index</p> </body> </html> JOEFYIUNM
  18. $ git push -u origin main • -uΦϓγϣϯ • --set-upstreamͱಉҙ

    • ଞͷϒϥϯν͸mainϒϥϯν͔Β෼ذ(্ྲྀϒϥϯν)ͱͯ͠ઃఆ ͢Δ $ git push
  19. CSSΛಡΜͰͳ͍ͷͰಡΈࠐ΋͏ <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link rel="stylesheet"

    href=“css/style.css”> <title>index</title> </head> <body> <h1>index</h1> <p>Hello index</p> </body> </html> JOEFYIUNM
  20. λΠτϧΛमਖ਼͠Α͏ <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <link rel="stylesheet"

    href=“”> <title>Hello index</title> </head> <body> <h1>index</h1> <p>Hello index</p> </body> </html> JOEFYIUNM
  21. $ git pull • ϦϞʔτϦϙδτϦߋ৽ࠩ෼ΛϩʔΧϧϦϙδτϦʹ࣋ͬͯ͘Δ warning: Pulling without specifying how

    to reconcile divergent branches is discouraged. You can squelch this message by running one of the following commands sometime before your next pull: git con fi g pull.rebase false # merge (the default strategy) git con fi g pull.rebase true # rebase git con fi g pull.ff only # fast-forward only Git2.27.0͔Β git pull ͚ͩͩͱ Warning͕ग़ΔΑ͏ʹͳΓ·ͨ͠
  22. Auto-merging index.html CONFLICT (content): Merge con fl ict in index.html

    Automatic merge failed; fi x con fl icts and then commit the result.
  23. 3 <head> 4 <meta charset="UTF-8"> 5 <<<<<<< HEAD 6 <link

    rel="stylesheet" href="css/style.css"> 7 <title>index</title> 8 ======= 9 <link rel="stylesheet" href=""> 10 <title>Hello index</title> 11 >>>>>>> 3be019ca9aeae74f4f3b876e8d9c7b61e5ba9902 12 </head> JOEFYIUNM
  24. ίϯϑϦΫτ͕ղফͨ͠Β ίϛοτ͠Α͏ $ git add . $ git commit Merge

    branch 'dev' of github.com:takanashi66/git-project into dev # Con fl icts: # index.html # It looks like you may be committing a merge. # If this is not correct, please run # git update-ref -d MERGE_HEAD # and try again.
  25. diff --git a/index.html b/index.html index 12f6444..84a776d 100644 --- a/index.html +++

    b/index.html @@ -2,8 +2,8 @@ <html lang="ja"> <head> <meta charset="UTF-8"> - <link rel="stylesheet" href="css/style.css"> - <title>index</title> + <link rel="stylesheet" href=""> + <title>Hello index</title> </head> <body> <h1>index</h1>
  26. $ git stash • ϫʔΩϯάπϦʔͷ಺༰ΛҰ࣌తʹୀආ͢Δ $ git stash save “ϝοηʔδ”

    • ϫʔΩϯάπϦʔͷ಺༰ΛϝοηʔδΛ͚ͭͯҰ࣌తʹୀආ͢Δ $ git stash pop • Ұ࣌తʹୀආͨ͠มߋΛϫʔΩϯάπϦʔʹదԠ͢Δ and more …
  27. ͓·͚ git reset --hardͰ໭Γ͗ͯ͢͠·ͬͨ৔߹ͷରॲ๏ * 27561a6 - (HEAD -> main)

    add p (30 seconds ago) * 831a227 - add h1 (75 seconds ago) * dbe6a2b - add index (2 minutes ago) ͜͜·Ͱ໭Γ͍ͨ
  28. ͓·͚ git reset --hardͰ໭Γ͗ͯ͢͠·ͬͨ৔߹ͷରॲ๏ * 27561a6 - (HEAD -> main)

    add p (30 seconds ago) * 831a227 - add h1 (75 seconds ago) * dbe6a2b - add index (2 minutes ago) ؒҧͬͯͬͪ͜Λ ࢦఆͯ͠͠·ͬͨ $ git reset --hard dbe6a2b
  29. ͓·͚ git reset --hardͰ໭Γ͗ͯ͢͠·ͬͨ৔߹ͷରॲ๏ * dbe6a2b - add index (2

    minutes ago) ໭Γ͗ͯ͢ Ҏ͕߱ফ͑ͯ͠·ͬͨ $ git reset --hard dbe6a2b
  30. ͓·͚ git reset --hardͰ໭Γ͗ͯ͢͠·ͬͨ৔߹ͷରॲ๏ $ git re fl og -n

    4 * dbe6a2b (HEAD -> main) HEAD@{0}: reset: moving to dbe6a2b * 27561a6 HEAD@{1}: commit (amend): add p * 52ab2f9 HEAD@{2}: commit: add h1 * 831a227 HEAD@{3}: commit: add h1 ফ͑ͯ͠·ͬͨ ίϛοτID͕֬ೝͰ͖Δ ࠷ޙͷ4͸೚ҙͷ਺ࣈɺ5ͳΒաڈͷཤྺ͕5ݸݟΕΔ amendͯ͠Δͷ͸ؾʹ͠ͳ͍Ͱ….
  31. ͓·͚ git reset --hardͰ໭Γ͗ͯ͢͠·ͬͨ৔߹ͷରॲ๏ $ git reset --hard 831a227 *

    dbe6a2b (HEAD -> main) HEAD@{0}: reset: moving to dbe6a2b * 27561a6 HEAD@{1}: commit (amend): add p * 52ab2f9 HEAD@{2}: commit: add h1 * 831a227 HEAD@{3}: commit: add h1 վΊͯࢦఆͷҐஔ·Ͱreset͢͢Ε͹͍͍