LoginSignup
10
10

More than 5 years have passed since last update.

メモ)Gitリセットをリモートに強制プッシュしたい。

Posted at

どこまで戻すか決める
git logしてコミット履歴を確認

まず git log してコミット履歴を確認します。
以下のような感じのものが出てきます。

$ git log
commit 61ea04eed2b4a4edc265c53827c5b05eb0de64cf
Author: hogehoge fugafuga@example.com
Date: Fri Aug 31 12:06:43 2012 +0900
 
Update pom.xml
 
commit d7589cfeddb10d36500ea7b9aea45ce470c01e0e
Author: hogehoge fugafuga@example.com
Date: Thu Aug 30 13:44:43 2012 +0900
 
Update readme.md
 
commit 464afea34504d42c4ea02b770fd425457b5e9b94
Author: hogehoge fugafuga@example.com
Date: Thu Aug 30 13:28:02 2012 +0900
 
first commit
 

戻りたい時点のcommitのハッシュ値をメモる

戻りたい時点のコミットのハッシュ値をメモります。
例えば上記の例で、一番下のfirst commitに戻りたい場合は、

commit 464afea34504d42c4ea02b770fd425457b5e9b94
Author: hogehoge fugafuga@example.com
Date: Thu Aug 30 13:28:02 2012 +0900
 
first commit
 

の「464afea34504d42c4ea02b770fd425457b5e9b94」がハッシュ値となります。

git reset —hardする

いよいよ禁断の git reset —hard します。

$ git reset --hard ハッシュ値

上記の例では、

$ git reset --hard 464afea34504d42c4ea02b770fd425457b5e9b94

となります。

戻した結果をpushする

戻した結果をpushします。
-fをつけつつハッシュ値をつけて強制pushします。

$ git push -f origin ハッシュ値:master

上記の例では、

$ git push -f origin 464afea34504d42c4ea02b770fd425457b5e9b94:master

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10