コミットした後で「やっぱりこのcommitはなかったことにしたい」というときは、
1 | $ git reset --hard HEAD^ |
を使います。
今、Gitのログが
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | $ git --no-pager log commit ee8831f07fcd5007816ef6e75682b826659a79cd Author: tomohiro <tomohiro@example.com> Date: Fri Jan 1 20:51:25 2016 +0900 add URL add the URL of the Ragtimeblues commit ab374c5f64e3de33b079b9e013ac2cec7830935d Author: tomohiro <tomohiro@example.com> Date: Fri Jan 1 16:57:09 2016 +0900 first commit |
となっているとき、一つ前に戻してみます。
1 2 | $ git reset --hard HEAD^ HEAD is now at ab374c5 first commit |
これで、OKです。再度ログを確認してみると
1 2 3 4 5 6 | $ git --no-pager log commit ab374c5f64e3de33b079b9e013ac2cec7830935d Author: tomohiro <tomohiro@example.com> Date: Fri Jan 1 16:57:09 2016 +0900 first commit |
となっており、sample.txtの内容も
1 2 | $ cat sample.txt Ragtimeblues |
と、最初のコミット内容に戻っています。