9. Git のしくみ
ONE PLAYER GAME
コミット
= スナップショット
master
過去 未来
topic
ファイルのスナップショットの集合のように考える。
Pro Git - Pro Git 1.3 使い始める Gitの基本 http://progit.org/book/ja/ch1-3.html
UT Startup Gym
10. コミットのしくみ
ONE PLAYER GAME
インデックス
ワーキングツリー
UT Startup Gym
11. コミットのしくみ
ONE PLAYER GAME
インデックス
ワーキングツリー
UT Startup Gym
12. コミットのしくみ
ONE PLAYER GAME
committed
git commit
インデックス
git status git add
ワーキングツリー
UT Startup Gym
13. コミットのしくみ
ONE PLAYER GAME
git log
git diff
UT Startup Gym
14. ONE PLAYER GAME
$ git init #レポジトリ (スナップショットの集合) の作成
$ touch hoge
$ git status
$ git add hoge
$ git status
$ git commit -m “first set”
$ git log
$ git status
$ vim hoge #適当に編集
$ git status
$ git diff
$ git add . #untrackedまたはmodifiedをすべてステージング
$ git commit -m “modified hoge to ...”
$ git log
...
UT Startup Gym
15. もとに戻す
ONE PLAYER GAME
• git add を取り消す
$ git reset HEAD
※ HEAD: 現在編集中のコミットのこと
• ファイル hoge をコミットID 785b... の時点に戻したい
$ git checkout 785b hoge
-> 785b... の時点のものになった hoge がステージングされる
-> 適宜修正して commit する
• HEAD^^^ = HEAD から3つ前のコミット
• --soft オプションや --hard オプション
• 実際は git が吐いてくれるコメント頼りです(丁寧!)。
git reset についてもまとめてみる-murankの日記- http://d.hatena.ne.jp/murank/20110327/1301224770 UT Startup Gym
16. Git の本領発揮は複数プレイ
MULTI PLAYER GAME
• 高度なマージ機能
• 常に最新のコードを共有
• 詳細な編集ログ
UT Startup Gym
17. ベアリポジトリ
MULTI PLAYER GAME
• ワーキングツリーを持たないリポジトリ
-> コミットにしか興味を持っていません的な
-> 実務的には push, pull が可能なリポジトリ
サーバのベアリポジトリ
dev.git
clone
push
pull
clone --bare
NEW!
ローカルのリポジトリ ローカルのリポジトリ ローカルのリポジトリ
dev/.git dev/.git dev/.git
UT Startup Gym
18. MULTI PLAYER GAME
$ vim ~/.ssh/config
Host ut-gym.jp
IdentityFile /path/to/***.pem
$ git clone ubuntu@ut-gym.jp:/home/ubuntu/git/gittest.git
$ cd gittest
$ ごにょごにょ
$ git commit -m “〇〇のために△△を××した”
$ git config --global user.name "Your Name"
$ git config --global user.email you@example.com
$ git pull origin master
$ コンフリクトするかも。解消するためにごにょごにょ
$ git push origin master
$ git log --graph
UT Startup Gym
19. コンフリクト
CONFLICT (content): Merge conflict in hoge
Automatic merge failed; fix conflicts and then commit the result.
$ cat hoge
<<<<<<< HEAD
a
b
c
=======
hoge
piyo
fuga
>>>>>>> 7fhtq23...
git 的にどちらを優先すればいいのかわからない状態。
コンフリクトに遭遇した人が責任をもって直します(笑)
UT Startup Gym