LoginSignup
12
11

More than 5 years have passed since last update.

【Git】remoteにpush済のファイルを以前の状態に戻す方法

Last updated at Posted at 2014-09-22

使いどころ

remoteにpushしたファイルをpush以前の状態に戻したい

$ git log --online
af71fff commit3
274c385 commit2 # hoge.rbを間違ってpushした
58408c8 commit1

commit2で変更するつもりのないファイルをcommitした場合、
そのファイルだけcommit1の状態に戻したい。

コマンド

git checkout -p {戻したい状態のコミットのハッシュ値} {戻したいファイル名}

上の例だと

git checkout -p 58408c8 hoge.rb

でhoge.rbだけcommit1の状態に戻せる。

12
11
1

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
12
11