Gitはじめてみた
自分用メモ
やったこと
ユーザ名、メールアドレス設定
※ここからはGit Bashでの操作
$ git config --global user.name "y_sumida"
$ git config --global user.email y.sumida.0201@gmail.com
リポジトリ作成
$ cd /c
$ mkdir gitwork
$ cd gitwork
$ mkdir project
$ cd project
$ git init
Initialized empty Git repository in c:/gitwork/project/.git/$ ls -a
. .. .git ※Gitの管理ディレクトリができている
コミット
$ git commit -m "Initial commit"
[master (root-commit) ee8ca33] Initial commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 hoge.txt$ git log
commit ee8ca33e9106651a8c2f90dbea38e33710dd4816
Author: y_sumida
Date: Mon Mar 19 22:40:42 2012 +0900Initial commit
更新&差分確認
$ cat hoge.txt ※エディタ等で編集後
hogehoge
fugafuga$ git diff
diff --git a/hoge.txt b/hoge.txt
index e9bc110..2471f6d 100644
--- a/hoge.txt
+++ b/hoge.txt
@@ -1 +1,2 @@
hogehoge
+fugafuga
更新内容のインデックス更新&コミット
$ git add hoge.txt
$ git diff --cached
diff --git a/hoge.txt b/hoge.txt
index e9bc110..2471f6d 100644
--- a/hoge.txt
+++ b/hoge.txt
@@ -1 +1,2 @@
hogehoge
+fugafuga$ git commit -m "Second commit"
[master 88c0d8e] Second commit
1 files changed, 1 insertions(+), 0 deletions(-)
ここまでのまとめ
基本的なサイクル
- リポジトリ作成(初回のみ)
- git init
- ファイルの作成/更新
- git add
- git commit
- 1,2の繰り返し
- その他
- ファイルツリーの構造は、HEAD→インデックス→ワーキングツリー
- HEAD=直近のコミット、インデックス=addしたもの?ワーキングツリー=ローカルの更新?
- git add インデックスの更新
- git commit HEADの更新
- commit 直後は HEAD = インデックス = ワーキングツリー ※違う場合ってあるのか?
- git diff ワーキングツリーとインデックスの差分
- git diff --cached HEADとインデックスの差分
- ファイルツリーの構造は、HEAD→インデックス→ワーキングツリー