3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

前のコミットの状態に戻したいときのコマンド

Last updated at Posted at 2019-11-25

はじめに

ログイン機能を作った後にdeviseというGemをインストールしたらエラーが多発。

エラー解消の方法が結局分からなかったので、バージョンを戻すことに。

ローカルリポジトリの状態を戻す

まずは、ローカルリポジトリで戻したいバージョンを探します。

$ git log 

すると

commit 277e01ad992515f7005f80cb9216fa551e50985e(ハッシュ値)

コミットコメント

みたいにズラーっと今までのコミットが表示されます。

そのバージョンに戻してみましょう。

$ git reset --hard 277e01ad992515f7005f80cb9216fa551e50985e
HEAD is now at 277e01a コミットコメント

このようにHEADが戻したいバージョンになれば成功みたいです。

リモートリポジトリの状態を戻す

次に、リモートリポジトリの操作をしていきます。

普通にpushしても競合しちゃうので

$ git push origin +master

のようにpushしたいmasterの前に「+」をつけます。

これでローカルリポジトリもリモートリポジトリも、元通り!

ぼやき

ブランチを切っておいた方がよかったですよねこれは。
ブランチの概念がわかっていないので勉強します。。。

あと、途中からGem deviceをインストールするときの対処法あれば教えてください。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?