gitをいじる会(`ω´)キリッ〜その2

第2回のgit勉強会だよーγ(▽´ )ツヾ( `▽)ゞ
前回はこちらー
http://d.hatena.ne.jp/nashuaki/20120814/1344954499


まずはローカルリポジトリを最新にしよう!

[nashuaki@hostname nashuaki_tips]$ git pull -u origin master

first.txtの最後の行に、
mumumu
を追加してみたよ。

ワーキングdirとステージ(addしたとこ)の差分

[nashuaki@hostname nashuaki_tips]$git diff .
diff --git a/first.txt b/first.txt
index b400f6a..06a9b00 100644
--- a/first.txt
+++ b/first.txt
@@ -1,2 +1,3 @@
 hello git!
 bye
+mumumu

ワーキングdirとローカルリポジトリの差分

[nashuaki@hostname nashuaki_tips]$git diff HEAD
diff --git a/first.txt b/first.txt
index b400f6a..06a9b00 100644
--- a/first.txt
+++ b/first.txt
@@ -1,2 +1,3 @@
 hello git!
 bye
+mumumu

ローカルリポジトリとステージの差分

[nashuaki@hostname nashuaki_tips]$git diff --cached

first.txtをステージにあげてみた。

ワーキングdirとステージ(addしたとこ)の差分

[nashuaki@hostname nashuaki_tips]$git diff .

ワーキングdirとローカルリポジトリの差分

[nashuaki@hostname nashuaki_tips]$git diff HEAD
diff --git a/first.txt b/first.txt
index b400f6a..06a9b00 100644
--- a/first.txt
+++ b/first.txt
@@ -1,2 +1,3 @@
 hello git!
 bye
+mumumu

ローカルリポジトリとステージの差分

[nashuaki@hostname nashuaki_tips]$git diff --cached
diff --git a/first.txt b/first.txt
index b400f6a..06a9b00 100644
--- a/first.txt
+++ b/first.txt
@@ -1,2 +1,3 @@
 hello git!
 bye
+mumumu


ここでローカルリポジトリにコミット

ワーキングdirとステージ(addしたとこ)の差分

[nashuaki@hostname nashuaki_tips]$git diff .

ワーキングdirとローカルリポジトリの差分

[nashuaki@hostname nashuaki_tips]$git diff HEAD

ローカルリポジトリとステージの差分

[nashuaki@hostname nashuaki_tips]$git diff --cached

これで
ワーキングdir
=ステージ
=ローカルリポジトリ
の状態

fufufuの追加ー

[nashuaki@hostname nashuaki_tips]$ git diff .
diff --git a/first.txt b/first.txt
index 06a9b00..5b48c23 100644
--- a/first.txt
+++ b/first.txt
@@ -1,3 +1,4 @@
 hello git!
 bye
 mumumu
+fufufu
[nashuaki@hostname nashuaki_tips]$ git add first.txt

heheheの追加ー

[nashuaki@hostname nashuaki_tips]$ git diff .
diff --git a/first.txt b/first.txt
index 5b48c23..ddf996c 100644
--- a/first.txt
+++ b/first.txt
@@ -2,3 +2,4 @@ hello git!
 bye
 mumumu
 fufufu
+hehehe


ステージにあげたものをきり戻すよ!

[nashuaki@hostname nashuaki_tips]$ git reset first.txt
Unstaged changes after reset:
M     first.txt
[nashuaki@hostname nashuaki_tips]$ git diff first.txt
diff --git a/first.txt b/first.txt
index 06a9b00..ddf996c 100644
--- a/first.txt
+++ b/first.txt
@@ -1,3 +1,5 @@
 hello git!
 bye
 mumumu
+fufufu
+hehehe

[nashuaki@hostname nashuaki_tips]$ cat first.txt
hello git!
bye
mumumu
fufufu
hehehe
[nashuaki@hostname nashuaki_tips]$ git checkout -- first.txt

[nashuaki@hostname nashuaki_tips]$ git diff first.txt

[nashuaki@hostname nashuaki_tips]$ cat first.txt
hello git!
bye
mumumu

checkoutしちゃうとワーキングのみの変更はかき消されちゃうよ(ノД`)・゜・。

ちなみに、
ローカルリポジトリにコミットしたものをもとに戻す場合は、

[nashuaki@hostname nashuaki_tips]$ git chekout HEAD -- filename

[nashuaki@hostname nashuaki_tips]$ git reset HEAD^ filename

diffはだいぶなれたけど、
resetとかはなんかややこい(●´⌓`●)
この辺参考になりそうかなー
http://d.hatena.ne.jp/murank/20110320/1300619118
http://d.hatena.ne.jp/murank/20110327/1301224770
http://redtower.plala.jp/2010/09/30/git-git-reset.html

とりあえずきりがいいのでここまでー!
今日はブランチまでやったんだけど、それは別更新にしておきます。