[Git] ファイルを特定のコミット状態まで戻す

memo.

[markdown]

## ファイルのlogを確認する

“`
% git log test/fixtures/products.yml
commit c3ee1df1de461a1ff98bd8f6c883ff2a2ee08e8a
Author: Taro Yamada
Date: Tue Aug 27 17:53:08 2013 +0900
Validation
commit 615c1953f81e9b69c9b187d2d6778164e16d2c3f
Author: Taro Yamada
Date: Tue Aug 27 15:59:18 2013 +0900
Depot Scaffold
“`

## ファイル内容を確認する

戻したい状態のファイル内容を確認する。

“`
% git show 615c1953f81e test/fixtures/products.yml
commit 615c1953f81e9b69c9b187d2d6778164e16d2c3f
Author: Taro Yamada
Date: Tue Aug 27 15:59:18 2013 +0900
Depot Scaffold
diff –git a/test/fixtures/products.yml b/test/fixtures/products.yml
new file mode 100644
index 0000000..979433b
— /dev/null
+++ b/test/fixtures/products.yml
@@ -0,0 +1,13 @@
+# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixtur
+
+one:
+ title: MyString
+ description: MyText
+ image_url: MyString
+ price: 9.99
+
+two:
+ title: MyString
+ description: MyText
+ image_url: MyString
+ price: 9.99
“`

もしくは : で繋げる。

“`
% git show 615c1953f81e:test/fixtures/products.yml
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/Fixture
one:
title: MyString
description: MyText
image_url: MyString
price: 9.99
two:
title: MyString
description: MyText
image_url: MyString
price: 9.99
“`

## checkoutして特定のコミット状態に戻す

“`
% git checkout 615c1953f81e test/fixtures/products.yml
% git status
# On branch master
# Changes to be committed:
# (use “git reset HEAD …” to unstage)
#
# modified: test/fixtures/products.yml
“`

[/markdown]