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

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

031a9b08d40f0ebb0bc04648c4bc7897?s=128

masuyama13

August 22, 2020
Tweet

Transcript

  1. GIT RESET ࠓ౓ͦ͜ཧղ͢Δ 2020.08.22 FJORD BOOT CAMP LTձ

  2. ൃද಺༰ GIT RESET ▸ git reset ͷಈ͖ ▸ ——softɺ——hardɺΦϓγϣϯলུʢ——mixedʣ ▸

    HEAD ͱ͸ ▸ ΠϯσοΫεͱ͸ ࠓ౓ͦ͜ཧղ͢Δ
  3. ࣗݾ঺հ @masuyama13 ‣ ڈ೥12݄ʙ FjordBootCamp ࢀՃ ‣ ݱࡏͷϓϥΫςΟε ‣ ΦϒδΣΫτࢦ޲ϓϩάϥϛϯά

    ‣ ݩࢢ໾ॴ৬һʢࣄ຿ʣ ‣ ࣛࣇౡग़਎ https://masuyama13.hatenablog.com/ 4݄͔Βຖ೔ϒϩάߋ৽தʂ
  4. ݱࡏͷ HEAD Λࢦఆ͞Εͨ ঢ়ଶʹ໭͢ɻ git reset Reset current HEAD to

    the specified state
  5. HEAD Λ໭͢ git reset —-softɹHEAD ͚ͩ໭͢ [—-mixed]ɹΠϯσοΫε΋໭͢ —-hardɹΠϯσοΫεͱϫʔΫπϦʔ΋໭͢

  6. ϫʔΫπϦʔ git commit git add ϦϙδτϦ master A A A

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

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

    A A HEAD master HEAD master A A A git commit git add ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  9. ϫʔΫπϦʔ ϦϙδτϦ 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 ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  10. ϫʔΫπϦʔ ϦϙδτϦ 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 ͜ͷίϛοτऔΓফ͍ͨ͠ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  11. HEAD Λ໭͢ git reset —-softɹHEAD ͚ͩ໭͢ [—-mixed]ɹΠϯσοΫε΋໭͢ —-hardɹΠϯσοΫεͱϫʔΫπϦʔ΋໭͢

  12. ϫʔΫπϦʔ ϦϙδτϦ 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~ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  13. ϫʔΫπϦʔ ϦϙδτϦ 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~ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  14. ϫʔΫπϦʔ ϦϙδτϦ 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~ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  15. ݁ߏ୯७ʁ

  16. ΠϯσοΫε ͬͯԿʁ ʢεςʔδϯάΤϦΞʣ ίϛοτ͢Δલʹొ࿥͠ͳ͍ͱ ͍͚ͳ͍৔ॴɾɾɾ ਖ਼௚ɺਂ͘ߟ͑ͨ͜ͱͳ͍

  17. git commit ϫʔΫπϦʔ ϦϙδτϦ git add B B B A

    A A A A git commit git add HEAD master HEAD master ࠩ෼͚ͩ צҧ͍ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  18. 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 ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  19. 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͸ΠϯσοΫε͔Β ফ͑ͪΌ͏!? ˞ޡΓͰ͢ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  20. ϫʔΫπϦʔ git commit git add ϦϙδτϦ HEAD master A A

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

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

    git commit git add git ls-files HEAD master ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ A B
  23. 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 औΓফ͢ ΠϯσοΫε ʢεςʔδϯάΤϦΞʣ
  24. ࠓ౓ͦ͜ཧղ͢Δ GIT RESET ·ͱΊ —-softɹHEAD ͚ͩ໭͢ [—-mixed]ɹHEAD ͱΠϯσοΫεΛ໭͢ —-hardɹHEAD ͱΠϯσοΫεͱϫʔΫπϦʔΛ໭͢

    git reset ࠩ෼Ͱ͸ͳ͘ɺίϛοτީิΛؙ͝ͱίϐʔͨ͠΋ͷ ͕อଘ͞Ε͍ͯΔ ΠϯσοΫεʢεςʔδϯάΤϦΞʣ
  25. ࠓ౓ͦ͜ཧղ͢Δ 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/ ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠