- 追加された行はこの色です。
- 削除された行はこの色です。
* コミットを取り消す [#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は修正前の状態に戻っている。
*** (コミットして時間が経っていて、すでに他者が修正を行っている可能性が高い場合の)コミットを取り消す [#g90f15df]
自分:
git commit -am 'XXX'
git push
他者:
git pull
git commit -am 'XXX'
自分:
git revert HEAD
git push
(他者)
git pull