LoginSignup
1
0

More than 3 years have passed since last update.

【git】pushしてしまった後に過去コミットに戻す方法

Last updated at Posted at 2020-11-24

gitでリモートにpushしてしまったけど、過去コミットに戻したい!そんな時の攻略法を簡潔に紹介

1 git log でコミットの 番号を確認する

$ git log

するとこんな感じで出てくる

commit 6ca09f7747e6ef84761d9d33a8373731836877eb (HEAD -> feature/tweet_list, origin/feature/tweet_list)
Author: nozomi <kkk@docomo.ne.jp>
Date:   Sun Nov 22 13:23:21 2020 +0900

    ページネーションを実装

commit cc2ede3638ebe6a6b768aa1fd269a2262e79d400
Author: nozomi <kkk@docomo.ne.jp>
Date:   Sun Nov 22 12:44:28 2020 +0900

    seed画像をビューに表示。アップロード画像をgit管理下から排除


今回は
seed画像をビューに表示。アップロード画像をgit管理下から排除に戻りたい想定で説明を続けます!

戻りたいコミットの番号をメモしとく
今回の場合は、cc2ede3638ebe6a6b768aa1fd269a2262e79d400 が番号になります。

2 git reset --hard 番号を使い、指定コミットに戻す。

今回は
seed画像をビューに表示。アップロード画像をgit管理下から排除に戻す処理なので、以下のように書きます。

$ git reset --hard cc2ede3638ebe6a6b768aa1fd269a2262e79d400

3 リモートリポジトリに強制push

git push -f origin HEAD

これにて完了です。

1
0
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
1
0