• 追加された行はこの色です。
  • 削除された行はこの色です。
* コミットを取り消す [#l4699c88]
* コミットを取り消す(過去のコミットに戻す) [#l4699c88]

*** コミットログを書き直したい/必要な修正ファイルをaddしてなかった(不要な修正ファイルをaddしてた) [#t6c54882]
 vi test.txt               # (1) test.txtを修正する。
 git add test.txt          # (2) test.txtをステージングする。
 git commit -am 'fixed'    # (3) コミットする。
 git reset --soft HEAD^    # (4) 上のコミットを取り消す。
 vi test2.txt              # (5) test2.txtを修正する。
 git add test2.txt         # (6) test2.txtをステージングする。
 git commit -am 'fixed 2 files' # (7) コミットし直す。
                                #     test.txt、test2,txt共に修正がコミットされた。
 
*** (コミットしてすぐの場合の)コミットを取り消す [#ve9b0731]
 vi test.txt               # (1) test.txtを修正する。
 git add test.txt          # (2) test.txtをステージングする。
 git commit -am 'fixed'    # (3) コミットする。     
 git reset --hard HEAD^    # (4) 上のコミットを取り消す。
                           #     コミットログ'fixed'は消え、test.txtは修正前の状態に戻っている。
*** コミットを取り消す(前回のコミットに戻す) [#pd3cc38f]

*** (コミットして時間が経っていて、すでに他者が修正を行っている可能性が高い場合の)コミットを取り消す [#g90f15df]
 vi test.txt            # (1) test.txtを修正する
 git add test.txt       # (2) test.txtをステージングする
 git commit -m 'fixed'  # (3) コミットする
 git reset --hard HEAD^ # (4) コミットを取り消す(HEADを前回のコミットに戻す)
                        #     コミットログ'fixed'は消え、test.txtは修正前の状態に戻っている
                              test.txt以外のファイルを修正したり、ステージングしていたとしても、前回のコミットの状態に戻っている

*** (コミットして時間が経っていて、すでに他者が修正を行っている可能性が高い場合の)コミットを取り消す [#u026cca0]
 自分:
 git commit -am 'XXX'
 git push

 他者:
 git pull
 git commit -am 'XXX'

 自分:
 git revert HEAD
 git push

 (他者)
 git pull


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS