1. git reset
git reset [<mode>] [<commit>]
mode--soft:HEADの移動--mixed:HEADの移動、インデックスの更新--hard:HEADの移動、インデックスの更新、作業ディレクトリの更新- デフォルトで
--mixedが指定される
commit- 巻き戻したいcommitを指定
- デフォルトでHEADが指定される
2. git resetの各モードについて
2-1. --soft (HEADの移動)
git reset --soft HEAD~
- 直近の
git commitを取り消す
2-2. --mixed (インデックスの更新)
git reset --mixed HEAD~
- 直近の
git commitとgit addを取り消す
2-3. --hard (作業ディレクトリの更新)
git reset --hard HEAD~
- 直近の
git commitとgit addと作業ディレクトリの変更を取り消す
3. まとめ
--soft:HEAD が指し示すブランチを移動する (--softを使うと処理はここで終了)--mixed:--soft+ インデックスの内容を HEAD と同じにする (--mixedを使うと処理はここで終了)--hard:--soft+--mixed+ 作業ディレクトリの内容をインデックスと同じにする
【参考】