Mais conteúdo relacionado
Semelhante a 実践 Git - 低レベルに知る Git (20)
実践 Git - 低レベルに知る Git
- 18. git-flow
$ git flow init
$ git flow feature start branch_name
$ git flow feature end branch_name
$ git flow hotfix
$ git flow release
- 19. legit - Git Workflow for Humans
$ git switch <branch>
$ git sync
$ git publish
$ git unpublish
$ git harvest
$ git sprout
$ git graft
$ git branches
- 23. Git を実践的に使う上で⽋かせない
⾼レベルな機能
分散リポジトリ
add --patch
merge, pull --rebase
stash, reflog
rebase -i による歴史の改変
- 27. リポジトリの作成
$ mkdir sandbox && cd sandbox
$ git init
$ tree .git
.git
├── HEAD # 現在チェックアウトしてるブランチ
├── config
├── description
├── hooks
│ └─各種 hook スクリプト
├── info
│ └── exclude
├── objects # オブジェクトデータベース
│ ├── info
│ └── pack
└── refs # リファレンス(ブランチ, タグなど)
└── heads
└── tags
- 33. オブジェクト ID は SHA-1 ハッシュ
$ echo 'Hello, World!' > greeting
$ git hash-object greeting
8ab686eafeb1f44702738c8b0f24f2567c36da6d
- 34. blob はファイル名に関係なく
中⾝が同じならば同じ ID
$ echo 'Hello, World!' > greeting2
$ git hash-object greeting greeting2
8ab686eafeb1f44702738c8b0f24f2567c36da6d
8ab686eafeb1f44702738c8b0f24f2567c36da6d
- 35. オブジェクトはオブジェクトデータベースに
ファイルで管理される
先頭2桁のディレクトリ名/残り38桁のファイル名
$ git add greeting
$ tree .git
.git # (⾊々省略)
├── index # インデックス
└── objects
└─ 8a
└── b686eafeb1f44702738c8b0f24f2567c36da6d
$ git cat-file -t 8ab6
blob
$ git cat-file blob 8ab6
Hello, World!
- 36. オブジェクトは読み込み権限で作成される
⼀度作成されたオブジェクトは上書きされないことを⽰唆している
$ stat -c %A .git/objects/8a/b686eafeb1f44702738c8b0f24f2567c36da6d
-r--r--r--
- 37. 同じ内容の blob を追加してもオブジェクトは置換されない
更新時刻は変わらないので置換されていないことがわかる
$ stat -c %y .git/objects/8a/b686eafeb1f44702738c8b0f24f2567c36da6d
2012-04-23 09:43:12.000000000 +0900
$ git add greeting2
$ stat -c %y .git/objects/8a/b686eafeb1f44702738c8b0f24f2567c36da6d
2012-04-23 09:43:12.000000000 +0900
- 38. 削除してもオブジェクトデータベースから
消えない
$ git rm --cached greeting greeting2
rm 'greeting'
rm 'greeting2'
$ git cat-file blob 8ab6
Hello, World!
- 42. tree はコミット時に作られる
$ git add greeting
$ git commit -m 'added my greeting.'
[master (root-commit) 77d0330] added my greeting.
1 file changed, 1 insertion(+)
create mode 100644 greeting
$ git cat-file commit HEAD # 最新コミットの中⾝をみる
tree 2da064c4206cb1e94a20a99c2cd2e19f3d193b74
author Youhei Nitta <me@youhei.jp> 1335212302 +0900
committer Youhei Nitta <me@youhei.jp> 1335212302 +0900
added my greeting.
$ git cat-file -t 2da0
tree
- 43. tree は blob や tree を保持している
$ git ls-tree 2da0
100644 blob 8ab686eafeb1f44702738c8b0f24f2567c36da6d greeting
$ mkdir subdir && mv greeting2
$ git add subdir
$ git commit -m 'added sub directory.'
$ git ls-tree HEAD
040000 tree 18e6d2abde0f316ff62e0c8093ca8f569910bf7d subdir
100644 blob 8ab686eafeb1f44702738c8b0f24f2567c36da6d greeting
$ git ls-tree 18e6
100644 blob 8ab686eafeb1f44702738c8b0f24f2567c36da6d greeting2
- 47. tree のオブジェクト ID を持つ
$ git cat-file commit HEAD
tree 680e36390174676a7343ec570f9f22d0632f4444
parent 77d03308354257e850041fd2d10448fc3a2c4c8b
author Youhei Nitta <me@youhei.jp> 1335213434 +0900
committer Youhei Nitta <me@youhei.jp> 1335213434 +0900
added sub directory.
$ git ls-tree commit 680e
040000 tree 18e6d2abde0f316ff62e0c8093ca8f569910bf7d subdir
100644 blob 8ab686eafeb1f44702738c8b0f24f2567c36da6d greeting
- 48. 親コミットのオブジェクト ID を持つ(最初のコミットを除く)
$ git cat-file commit HEAD
tree 680e36390174676a7343ec570f9f22d0632f4444
parent 77d03308354257e850041fd2d10448fc3a2c4c8b
author Youhei Nitta <me@youhei.jp> 1335213434 +0900
committer Youhei Nitta <me@youhei.jp> 1335213434 +0900
added sub directory.
$ git cat-file -t 77d0
commit
$ git cat-file commit 77d0
tree 2da064c4206cb1e94a20a99c2cd2e19f3d193b74
author Youhei Nitta <me@youhei.jp> 1335212302 +0900
committer Youhei Nitta <me@youhei.jp> 1335212302 +0900
added my greeting.
- 49. マージコミットは⼆つの親コミットを持つ
(少し⾼レベルに戻ります)
$ git branch fukuoka
$ git checkout fukuoka
$ echo 'Hello, Fukuoka!' > greeting2
$ git add greeting2
$ git commit -m 'added another greeting.'
$ git checkout master
$ git merge fukuoka -m 'merged fukuoka branch.'
$ git cat-file commit HEAD
tree 2fb79db8e8b4ab0f704a056754b434ff2a5435b9
parent ae3bc73b86e8ea701496122f4ea7ec5e29cab979
parent 5d8fc0a8aef3930dac4347bdfda950cec83bde8c
author Youhei Nitta <me@youhei.jp> 1335215713 +0900
committer Youhei Nitta <me@youhei.jp> 1335215713 +0900
merged fukuoka branch.
- 50. commit object についてわかったこと
必ず tree を持っている
つまりコミット時点でのツリーの
完全な状態(スナップショット)を持っている
parent を持っている
マージコミットは parent を⼆つ持っている
つまり parent を辿れば「履歴」を構成できる
- 59. branch は references
$ cat .git/refs/heads/master
41219f49d28b936482be893a6ca3b5a77443c78a
$ git cat-file commit master
tree 2fb79db8e8b4ab0f704a056754b434ff2a5435b9
parent ae3bc73b86e8ea701496122f4ea7ec5e29cab979
parent 5d8fc0a8aef3930dac4347bdfda950cec83bde8c
author Youhei Nitta <me@youhei.jp> 1335215713 +0900
committer Youhei Nitta <me@youhei.jp> 1335215713 +0900
Merge branch 'fukuoka'
$ git cat-file commit 41219f49d28b936482be893a6ca3b5a77443c78a
tree 2fb79db8e8b4ab0f704a056754b434ff2a5435b9
parent ae3bc73b86e8ea701496122f4ea7ec5e29cab979
parent 5d8fc0a8aef3930dac4347bdfda950cec83bde8c
author Youhei Nitta <me@youhei.jp> 1335215713 +0900
committer Youhei Nitta <me@youhei.jp> 1335215713 +0900
Merge branch 'fukuoka'
- 60. HEAD は symbolic references
他の references へのポインタで表現されている
$ cat .git/refs/HEAD
ref: refs/heads/master
$ git symbolic-ref HEAD
refs/heads/master
$ git cat-file commit HEAD
tree 2fb79db8e8b4ab0f704a056754b434ff2a5435b9
parent ae3bc73b86e8ea701496122f4ea7ec5e29cab979
parent 5d8fc0a8aef3930dac4347bdfda950cec83bde8c
author Youhei Nitta <me@youhei.jp> 1335215713 +0900
committer Youhei Nitta <me@youhei.jp> 1335215713 +0900
Merge branch 'fukuoka'
- 61. tag も references
$ git tag v0.0.1
$ cat .git/refs/tags/v0.0.1
41219f49d28b936482be893a6ca3b5a77443c78a
$ git cat-file commit v0.0.1
tree 2fb79db8e8b4ab0f704a056754b434ff2a5435b9
parent ae3bc73b86e8ea701496122f4ea7ec5e29cab979
parent 5d8fc0a8aef3930dac4347bdfda950cec83bde8c
author Youhei Nitta <me@youhei.jp> 1335215713 +0900
committer Youhei Nitta <me@youhei.jp> 1335215713 +0900
Merge branch 'fukuoka'
$ git cat-file commit 41219f49d28b936482be893a6ca3b5a77443c78a
tree 2fb79db8e8b4ab0f704a056754b434ff2a5435b9
parent ae3bc73b86e8ea701496122f4ea7ec5e29cab979
parent 5d8fc0a8aef3930dac4347bdfda950cec83bde8c
author Youhei Nitta <me@youhei.jp> 1335215713 +0900
committer Youhei Nitta <me@youhei.jp> 1335215713 +0900
Merge branch 'fukuoka'
- 62. tag と branch の違い
実はほとんど同じ
branch は commit に合わせて変動する
逆に tag は変動しない branch といえる
- 64. ここまでの低レベルな観点だけで、
下記の⾼レベルな視点に
⾃分なりの回答ができるはずです
いくら分散しても⽭盾が発⽣しない理由
ブランチの切り替えが⾼速な理由
reflog で過去のどの時点にも戻れる理由
差分はどこから取り出しいつ計算するか推測
SHA-1 ハッシュ値が衝突時に Git はどう振る舞うか推測
- 65. おまけ
SHA-1 ハッシュ値の衝突について⼩噺
SHA-1 の衝突を⾒るにはどうしたらいいのか、ひとつの例をごらんに⼊
れましょう。
地球上の⼈類 65 億⼈が全員プログラムを書いていたとします。そして
その全員が、Linux カーネルのこれまでの開発履歴 (100 万の Git オブジ
ェクト) と同等のコードを⼀秒で書き上げ、⾺⿅でかい単⼀の Git リポジ
トリにプッシュしていくとします。これを五年間続けたとして、SHA-1
オブジェクトの衝突がひとつでも発⽣する可能性がやっと 50% になり
ます。
それよりも「あなたの所属する開発チームの全メンバーが、同じ夜にそ
れぞれまったく無関係の事件で全員オオカミに殺されてしまう」可能性
のほうがよっぽど⾼いことでしょう。
ProGit 6.1 リビジョンの選択 より