概要
ファイルを編集前の状態に戻す
内容
以下のコマンドでファイルを編集前の状態に戻します。
git checkout <ファイル名>
サンプル
・Gitから最新ファイル取得
・hoge.txtを編集
・status,diffを確認=>差分あり
・checkoutを行う
・status,diffを確認=>差分なし
$git status # On branch master # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: hoge.txt # no changes added to commit (use "git add" and/or "git commit -a") $git diff diff --git a/hoge.txt b/hoge.txt index 753cb20..0449994 100644 --- a/hoge.txt +++ b/hoge.txt @@ -1,3 +1,3 @@ test test2 - +test3 $git checkout hoge.txt $git status # On branch master nothing to commit (working directory clean) $git diff