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

今度こそ理解する/git-reset-200822

 今度こそ理解する/git-reset-200822

masuyama13

August 22, 2020
Tweet

More Decks by masuyama13

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ @masuyama13 ‣ ڈ೥12݄ʙ FjordBootCamp ࢀՃ ‣ ݱࡏͷϓϥΫςΟε ‣ ΦϒδΣΫτࢦ޲ϓϩάϥϛϯά

    ‣ ݩࢢ໾ॴ৬һʢࣄ຿ʣ ‣ ࣛࣇౡग़਎ https://masuyama13.hatenablog.com/ 4݄͔Βຖ೔ϒϩάߋ৽தʂ
  2. ϫʔΫπϦʔ git commit git add ϦϙδτϦ master A A A

    touch A ϒϥϯνɿ ɾಛఆͷίϛοτΛࢦࣔ͢͠ϙΠϯλ ɾσϑΥϧτ͕ master ɾ࠷ॳͷίϛοτΛͨ࣌͠఺Ͱൃੜ ɾࢬ෼͔Εͷઌ୺ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ ίϛοτ༧ఆͷ΋ͷΛొ࿥͢Δ৔ॴ ϑΝΠϧฤूͳͲΛߦ͏࡞ۀ৔ॴ ʮίϛοτʯ ͕Ͱ͖Δ
  3. ϦϙδτϦ ϫʔΫπϦʔ git commit git add HEAD master ɾݱࡏͷϒϥϯνΛࢦࣔ͢͠ϙΠϯλ ɾ࣍ͷίϛοτͷ਌ʹͳΔ

    A A A ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ ίϛοτ༧ఆͷ΋ͷΛొ࿥͢Δ৔ॴ ϑΝΠϧฤूͳͲΛߦ͏࡞ۀ৔ॴ ʮίϛοτʯ ͕Ͱ͖Δ
  4. ϫʔΫπϦʔ ϦϙδτϦ git commit git add B B B A

    A A HEAD master HEAD master A A A git commit git add ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  5. ϫʔΫπϦʔ ϦϙδτϦ git commit git add B B B A

    A A HEAD master A A A git commit git add git commit git add B B B A A A C C C HEAD master ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  6. ϫʔΫπϦʔ ϦϙδτϦ git commit git add B B B A

    A A A A A git commit git add git commit git add B B B A A A C C C HEAD master ͜ͷίϛοτऔΓফ͍ͨ͠ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  7. ϫʔΫπϦʔ ϦϙδτϦ git commit git add B B B A

    A A A A A git commit git add git commit git add B B B A A A C C C HEAD master HEAD master औΓফ͢ git reset —-soft HEAD~ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  8. ϫʔΫπϦʔ ϦϙδτϦ git commit git add B B B A

    A A A A A git commit git add git commit git add B B B A A A C C C HEAD master HEAD master औΓফ͢ git reset HEAD~ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  9. ϫʔΫπϦʔ ϦϙδτϦ git commit git add B B B A

    A A A A A git commit git add git commit git add B B B A A A C C C HEAD master HEAD master औΓফ͢ git reset —-hard HEAD~ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  10. git commit ϫʔΫπϦʔ ϦϙδτϦ git add B B B A

    A A A A git commit git add HEAD master HEAD master ࠩ෼͚ͩ צҧ͍ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  11. git commit ϫʔΫπϦʔ ϦϙδτϦ git add B B B A

    A A A A git commit git add git commit git add B B A A C C C HEAD master HEAD master ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  12. git commit ϫʔΫπϦʔ ϦϙδτϦ git add B B B A

    A A A A git commit git add git commit git add B B A A C C C HEAD master HEAD master git reset —-soft HEAD~2 औΓফ͢ B͸ΠϯσοΫε͔Β ফ͑ͪΌ͏!? ˞ޡΓͰ͢ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  13. ϫʔΫπϦʔ git commit git add ϦϙδτϦ HEAD master A A

    A ࣍ͷίϛοτͷεφοϓγϣοτ εφοϓγϣοτɿ ؙ͝ͱίϐʔͨ͠΋ͷ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  14. ϫʔΫπϦʔ git add A A ࣍ͷίϛοτͷεφοϓγϣοτ εφοϓγϣοτɿ ؙ͝ͱίϐʔͨ͠΋ͷ git ls-files

    ΠϯσοΫεʹ͋ΔϑΝΠϧͷϦετΛදࣔ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  15. ϫʔΫπϦʔ ϦϙδτϦ ʁʁʁ git add B A A A A

    git commit git add git ls-files HEAD master ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ A B
  16. git commit ϫʔΫπϦʔ ϦϙδτϦ git add B B B A

    A A A A A git commit git add git commit git add B B B A A A C C C HEAD master HEAD master git reset —-soft HEAD~2 औΓফ͢ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  17. ࠓ౓ͦ͜ཧղ͢Δ GIT RESET ·ͱΊ —-softɹHEAD ͚ͩ໭͢ [—-mixed]ɹHEAD ͱΠϯσοΫεΛ໭͢ —-hardɹHEAD ͱΠϯσοΫεͱϫʔΫπϦʔΛ໭͢

    git reset ࠩ෼Ͱ͸ͳ͘ɺίϛοτީิΛؙ͝ͱίϐʔͨ͠΋ͷ ͕อଘ͞Ε͍ͯΔ ΠϯσοΫεʢεςʔδϯάΤϦΞʣ
  18. ࠓ౓ͦ͜ཧղ͢Δ GIT RESET ࢀߟࢿྉ ▸ Git ▸ https://git-scm.com/ ▸ αϧઌੜͷGitೖ໳

    ▸ https://backlog.com/ja/git-tutorial/ ▸ GitͷεςʔδϯάྖҬͷਖ਼ମΛ୳Δ | ϝϧΧϦΤϯδχΞϦϯά ▸ https://engineering.mercari.com/blog/entry/2017-04-06-171430/ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠