#author("2017-11-28T20:12:21+09:00","default:Miyashita","Miyashita")
#author("2018-07-26T00:50:13+09:00","default:Miyashita","Miyashita")
*ある時点の状態へ戻す [#hac11aa2]
変な変更をしてしまってある時点の状態へ戻りたいとき.~
ローカルリポジトリでの話.~
**全体を指定のコミットのバーションに戻す [#qa1b4e82]
 $ git log --oneline
 e4a0e00 2nd commit
 5f870ca 1st commit
#codeprettify{{
$ git log --oneline
e4a0e00 2nd commit
5f870ca 1st commit
}}
となり,管理下のファイル全てを一つ前のコミットの状態へ戻すには,
 $ git reset --hard HEAD^
#codeprettify{{
$ git reset --hard HEAD^
}}
をする.HEAD^の部分は,5f870caのようなコミットのハッシュ値でもOK.~
HEAD^^とすると,2つ前のcommitの状態に戻ることになる.~
下記のようにもう一度logで確認すると,一番上にあったコミットがなくなっていることがわかる.
 $ git log --oneline
 5f870ca 1st commit
#codeprettify{{
$ git log --oneline
5f870ca 1st commit
}}
あるディレクトリ名を変更し,その中にGitで管理されているファイルと対象外のファイルが混ざっていると,上記のgit resetで戻した際にも対象外ファイルは戻らないので注意する.~

**特定のファイルだけ指定のコミットのバージョンに戻す [#h493039a]
ある1つのファイルをいじったらうまく回らなくなったとか,やっぱりやめたいという時は
 $ git checkout HEAD filename

#codeprettify{{
$ git checkout HEAD filename
}}

Front page   Edit Diff Attach Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes