.git/objectsã«ã¤ãã¦å°ã調ã¹ã¦ã¿ã
äºã®çºç«¯ã¯ããããªåºæ¥äºãä»äºã§gitã使ã£ã¦ãã¦ãéçºä¸ã®ã½ã¼ã¹ãããã«ããããã¤ããªãã¡ã¤ã«ããªãã¸ããªã«çªã£è¾¼ãã§ç®¡çãã¦ããæè¿ããã«git cloneããæã«æéãããããªã¼ã¨æã£ã¦è¦ããããªãã¸ããªãµã¤ãºã200Mbè¶ ãã¦ãï¼ï¼ããããè¦ãã.git/objects以ä¸ãè¥å¤§åãã¦ãããªãã ãããã¨æã£ã¦èª¿ã¹ã¦ã¿ãã
ãã¡ãã大å¤åèã«ãªãã¾ããï¼
ãã£ããã¾ã¨ã
- gitã§ã¯commitãtreeãblobã3種é¡ã®ãªãã¸ã§ã¯ãã§ãªãã¸ããªã表ç¾ãã¦ã
- blobããã¡ã¤ã«ãã®ãã®ããã ããã¡ã¤ã«åãªã©ã®ã¡ã¿ãã¼ã¿ã¯å«ã¾ãªã
- treeããã£ã¬ã¯ããªãblobãé ä¸treeã®ããã·ã¥å¤ãæã¡ãããã³ãããæç¹ã®ãã£ã¬ã¯ããªæ§é ã表ç¾ãããblobã®ã¡ã¿ãã¼ã¿ã¯treeãæã£ã¦ã
- commitãããæç¹ã®ãªãã¸ããªã表ãã³ããããã®ãã®ãcommit -> tree -> (blob|tree)*ã®é¢ä¿ã«ãªãã¨ç解ãã
- gitãªãã¸ã§ã¯ãã¯addãcommitãããã¿ã¤ãã³ã°ã§æ°ãããã®ãçã¾ãã
- ãã¡ã¤ã«ãä¿®æ£ãããã¨ããã®blobãªãã¸ã§ã¯ãã¨ãblobãå ¥ã£ã¦ãtreeãªãã¸ã§ã¯ããæ°ãããªã
- 以åã®gitãªãã¸ã§ã¯ãã¯ãã®ã¾ã¾æ®ã
- blobã¯ãã ã®ãã¡ã¤ã«ã³ãã¼ã§ã¯ãªããzlibã§å§ç¸®ãããç¶æ
ã«ãªã
- å ã®ãã¡ã¤ã«ãµã¤ãºã«ä¾åããããã大ããªãã¡ã¤ã«ãã½ãã½ãå¤æ´ããã¨ã»ã»ã»
- gitãªãã¸ã§ã¯ãã¯ä½ãã®ã¿ã¤ãã³ã°ã§packfileã«ã¾ã¨ãããã
- ãã£ã¹ã¯ã¹ãã¼ã¹ã®æå¹æ´»ç¨ã¨ããªãã¨ããã©ã®ã¿ã¤ãã³ã°ã§packããããã¯ããããªãã£ã
- bareã§ã¯unpackããç¶æ ã§ç®¡çããã¦ããcloneããã¿ã¤ãã³ã°ã§packãã¦éã£ã¦ããã¿ãã
é·ã 調ã¹ããã©ãæ´æ°é »åº¦ãé«ãããã¤ãµã¤ãºã大ãããã¡ã¤ã«ãgitã§ç®¡çããã®ã¯è³¢ããªããã¨ããçµè«ã«è³ã£ããä»åã®å ´åã ã¨ãã½ã¼ã¹ããã«ããããã¤ããªã ãããã½ã¼ã¹ã ããã¼ã¸ã§ã³ç®¡çããã¦ãã°ããããã ã»ã»ã»ã
å®éã«èª¿ã¹ã¦ã¿ãè¨é²
ããããgit commitããæã«ä½ãèµ·ããã®ã
commitããæ.git/objectsã«ãªãã¸ã§ã¯ããå¢ããããããå®éã«git commitãããä½ãèµ·ããã®ãããã¼ã«ã«ã«gitãªãã¸ããªä½ã£ã¦è©¦ãã¦ã¿ã
#ãã¼ã«ã«ã§ä½ã£ã空ã®ãªãã¸ããªãclone $ git clone localhost:/var/git/my_repo.git #.git/* 以å¤ã¯ä½ããªã $ ls -a . .. .git #.git/objectsã®ä¸èº«ã¯ãã£ã¬ã¯ããªã ã $ find .git/objects .git/objects .git/objects/info .git/objects/pack #ãã¡ã¤ã«ä½ã£ã¦ã¿ã (ãã®æç¹ã§ã¯.git/objectsã«ã¯å¤åãªã) echo "first commit" > first.txt #addããã.git/objectsã«ãã¡ã¤ã«ãå¢ãã $ git add first.txt $ find .git/objects .git/objects .git/objects/info .git/objects/pack .git/objects/5e .git/objects/5e/c586d228b5ff1e8c845c4ed8c2d01f3a159b24
addããæç¹ã§ä½ãã.git/objectsã«ãã¡ã¤ã«ãå¢ãã¦ãã
ãããããä»addãããã¡ã¤ã«ã®ããã·ã¥å¤ãªã®ããªã¼ã¨æã£ã¦è¦ãããã³ã´ãããã·ã¥å¤ã®ä¸ä½2æ¡ããã£ã¬ã¯ããªåã«ãªãããã
$ git hash-object first.txt 5ec586d228b5ff1e8c845c4ed8c2d01f3a159b24
cat-file -p [sha-1]ã§ãªãã¸ã§ã¯ãã®ä¸èº«ãè¦ãããããã
試ãã¦ã¿ãã¨ãä»ä½ã£ããã¡ã¤ã«ã ã£ãã
$ git cat-file -p 5ec586d228b5ff1e8c845c4ed8c2d01f3a159b24 first commit
ãªãã»ã©ãgitã£ã¦ãããã£ã¦ãªãã¸ã§ã¯ãã管çãã¦ãã®ãã
ããããã¾ãcommitãã¦ãªãã£ããã¨æãcommitãã¦ã¿ãã¨ããã«ä½ãå¢ããï¼ï¼
$ git commit -m "my first commit" $ find .git/objects -type f .git/objects/47/17b4c5681f5c31e733b36ad571b8c90b62a1e7 .git/objects/59/4f237fd0220226fb625e781e633ff22e104e5a .git/objects/5e/c586d228b5ff1e8c845c4ed8c2d01f3a159b24
git cat-file -tã§ãªãã¸ã§ã¯ãã®ã¿ã¤ãããããã
#ã³ããããããã¡ã¤ã«ã ã¨blob $ git cat-file -t 5ec586d228b5ff1e8c845c4ed8c2d01f3a159b24 blob #å¢ããæ®ãã®2ã¤ã¯treeã¨commit $ git cat-file -t 4717b4c5681f5c31e733b36ad571b8c90b62a1e7 commit $ git cat-file -t 594f237fd0220226fb625e781e633ff22e104e5a tree
ã¸ã¼commitãã®ãã®ããªãã¸ã§ã¯ãã«ãªãã®ãã確èªããã確ãã«ããã·ã¥å¤ãä¸è´ãã
$ git log -1 commit 4717b4c5681f5c31e733b36ad571b8c90b62a1e7 ...
ã§ãtreeã£ã¦ãªãã ï¼ã¨æã£ãã¨ããã§ãåèãµã¤ããè¦ã¦ç解ã
ããcommitæç¹ã§ã®ãã¡ã¤ã«ããªã¼ã表ç¾ããããã®ãã®ããããgit ls-treeã§ä¸èº«ãè¦ã¦ã¿ãã¨ããã¼ãªãã»ã©ãããã£ã¬ã¯ããªãä½ã£ããããã¤ãtreeã«ãªãããã ã
$ git ls-tree 594f237fd0220226fb625e781e633ff22e104e5a 100644 blob 5ec586d228b5ff1e8c845c4ed8c2d01f3a159b24 first.txt
ã¤ã¾ããcommit -> tree -> (blob|tree)* ãªé¢ä¿ã§1ã¤ã®commitã管çãããã®ãã¼ã
ããã¦ãã¡ã¤ã«åã¨ãã®blobã®ã¡ã¿æ
å ±ã¯treeãæã¤ã¨ã
å¤æ´ãå ¥ãã¨æ°ãããªãã¸ã§ã¯ããä½ããã
directory -> file1,file2 ãªé¢ä¿ã®æã£ã¦commitãã¨ã«ãªãã¸ã§ã¯ãä½ãããã®ããªï¼
#dir1ãä½ã£ã¦ããã®ä¸ã«2ã¤ããã¹ãã追å ãã $ mkdir dir1 $ echo "second commit" > dir1/second.txt $ echo "third commit" > dir1/third.txt $ git add --all $ git commit -m "added dir1/second.txt dir1/third.txt" $ find .git/objects -type f .git/objects/b5/abbe4d64d728c9b9468b515b0df03cebcdad06 .git/objects/47/17b4c5681f5c31e733b36ad571b8c90b62a1e7 .git/objects/2f/f0cc013f80a72af170879f7c91252348570649 .git/objects/59/4f237fd0220226fb625e781e633ff22e104e5a .git/objects/61/82892b5d9799fea00e13db79bcb46beff10204 .git/objects/c3/e1215a4e3ed4a6f732b7768c4b73a307de5f65 .git/objects/29/fa8de42d514b1d99739e51105d214df6f7ada6 .git/objects/5e/c586d228b5ff1e8c845c4ed8c2d01f3a159b24
ãã¼ãå¢ããå¢ããã1ã¤ãcommitã1ã¤ãã«ã¼ãã«ç¸å½ããtreeãæ®ããdir1ã®treeã¨2ãã¡ã¤ã«ã®blobããparentã¨ãã¦ãåã®commitã®ããã·ã¥å¤ãè¨é²ããã¦ãããªãã»ã©ãããããããã
#ä»åã®commitãªãã¸ã§ã¯ã $ git cat-file -t 6182892b5d9799fea00e13db79bcb46beff10204 commit #commitã®ä¸èº« $ git cat-file commit 6182892b5d9799fea00e13db79bcb46beff10204 tree b5abbe4d64d728c9b9468b515b0df03cebcdad06 parent 4717b4c5681f5c31e733b36ad571b8c90b62a1 #ã«ã¼ãç¸å½ã®treeã®ä¸èº« $ git ls-tree b5abbe4d64d728c9b9468b515b0df03cebcdad06 040000 tree 29fa8de42d514b1d99739e51105d214df6f7ada6 dir1 100644 blob 5ec586d228b5ff1e8c845c4ed8c2d01f3a159b24 first.txt #dir1ã®ãªãã¸ã§ã¯ãã®ä¸èº« $ git ls-tree 29fa8de42d514b1d99739e51105d214df6f7ada6 100644 blob 2ff0cc013f80a72af170879f7c91252348570649 second.txt 100644 blob c3e1215a4e3ed4a6f732b7768c4b73a307de5f65 third.txt
ããã§ãfirst.txtã®ããã·ã¥å¤ãå¤ãã£ã¦ãªããã¨ã«æ°ã¥ããå¤æ´ãå ¥ããªããªãã¸ã§ã¯ãã¯æ´æ°ãããªãã®ããªï¼
#dir1/second.txtãæ´æ°ãã¦ã¿ã $ echo "fourth commit" >> dir1/second.txt $ git commit -am "fourth commit to dir1/second.txt" #commitã®ããã·ã¥å¤ã調ã¹ã¦ $ git log -1 commit c0abb1b3f9d4d8e4414085f8d69ea9948009900e #commitã®ä¸èº«ã調ã¹ã¦ $ git cat-file commit c0abb1b3f9d4d8e4414085f8d69ea9948009900e tree 59fd1590accc6e58d3a6695f820ddeedb6d2b276 #treeã®ä¸ããdir1ã®ãªãã¸ã§ã¯ãã辿ã $ git ls-tree 59fd1590accc6e58d3a6695f820ddeedb6d2b276 040000 tree e53622b524682d1b33bda38a64581248dc9aaf46 dir1 100644 blob 5ec586d228b5ff1e8c845c4ed8c2d01f3a159b24 first.txt #dir1ãªãã¸ã§ã¯ãã®ä¸èº«ãè¦ã¦ã¿ã $ git ls-tree e53622b524682d1b33bda38a64581248dc9aaf46 100644 blob 2135c44150c46ddffabe9451f2dc7e3404012b19 second.txt 100644 blob c3e1215a4e3ed4a6f732b7768c4b73a307de5f65 third.txt
ãã¼ããªãã»ã©ããå¤æ´ããããã®ã ããªãã¸ã§ã¯ããå¢ããã¨ãdir1ã«å ¥ã£ã¦ããã¡ã¤ã«ãæ´æ°ããããããdir1ã®ããã·ã¥å¤ãæ°ãããªã£ã¦ããæ¯å丸ãã¨ãªãã¸ã§ã¯ãä½ãç´ãã¯éå¹çã ãããªã¼ã
blobã£ã¦ãã ã®ãã¡ã¤ã«ã³ãã¼ï¼
ããã¯ããã¨ãblobãªãã¸ã§ã¯ãã£ã¦ã¤ã¾ããã»ã¨ãã©ãã¡ã¤ã«ã³ãã¼ã¿ãããªç©ã£ã¦ãã¨ãªã®ãï¼ï¼ã¨æã£ã¦è©¦ãã¦ã¿ãã
#1Mbã®tmpfileãä½ã£ã¦ã¿ã¦ $ dd if=/dev/zero of=tempfile bs=1M count=1 $ ls -lh tempfile | awk '{print $5}' 1.0M #addãã¦ããã·ã¥å¤èª¿ã¹ã¦ $ git add tempfile $ git hash-object tempfile 9e0f96a2a253b173cb45b41868209a5d043e1437 #ãµã¤ãºãè¦ã¦ã¿ã㨠$ ls -lh .git/objects/9e/0f96a2a253b173cb45b41868209a5d043e1437 | awk '{print $5}' 4.6K
ãããã«ãããªãã¨ã¯ãªãããå§ç¸®ã¯ããã¦ã模æ§ã
åèãµã¤ãã«ããã°ã
Git㯠zlib ãç¨ãã¦æ°ããã³ã³ãã³ããå§ç¸®ãã¾ãã
http://git-scm.com/book/ja/Gitã®å å´-Gitãªãã¸ã§ã¯ã
ã¨ã®ãã¨ããã ã¾ãããã¨ãã¡ã¤ã«ã®å¤§ããã«æ¯ä¾ãããªãã¸ã§ã¯ããå¤æ´ã®ãã³ã«ä½ããã¦ããããã ï¼
ãããã¦ãã¨ã¯ãªãã¸ããªã®ãµã¤ãºã¯ã²ãããè¨ããä¸æ¹ãªããã»ã»ã»ï¼
Git ããã£ã¹ã¯ä¸ã«ãªãã¸ã§ã¯ããæ ¼ç´ããåæã®ãã©ã¼ãããã¯ãç·©ããªãã¸ã§ã¯ããã©ã¼ãããï¼loose object formatï¼ã¨å¼ã°ãã¾ããããã Git ã¯ãããã®ãªãã¸ã§ã¯ãã®ä¸ã®å¹¾ã¤ããã²ã¨ã¤ã®ãã¤ããªãã¡ã¤ã«ã«è©°ãè¾¼ãï¼pack upï¼ãã¨ãããã¾ãããã®ãã¤ããªãã¡ã¤ã«ã¯ã空ãã¹ãã¼ã¹ãä¿åãã¦ããå¹ççã«ããããã®ãããã¯ãã¡ã¤ã«ï¼packfileï¼ã¨å¼ã°ãã¾ãããã¾ãã«ããããã®ç·©ããªãã¸ã§ã¯ãããããä¸ã«ããã¨ãããgit gc ã³ãã³ããæåã§å®è¡ããã¨ããã¾ãã¯ããªã¢ã¼ããµã¼ãã«ããã·ã¥ããã¨ãã«ãGit ã¯ãããå®è¡ãã¾ãã
http://git-scm.com/book/ja/Git%E3%81%AE%E5%86%85%E5%81%B4-%E3%83%91%E3%83%83%E3%82%AF%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB
ãªãã»ã©ããããã«å¯¾çã¯ããã¦ãããã ãã¨ã¯ãããã©ã®ã¿ã¤ãã³ã°ã§packfileãä½ãããã®ãã¯ããããããã
ãã£ãããªã®ã§git gc試ãã¦ã¿ã¾ããã
#tempfileã«1è¡å ãã¦commit $ echo "fifth commit" >> tempfile $ git commit -am "fifth commit" #ä½ããããªãã¸ã§ã¯ãã¨ãµã¤ãºç¢ºèª $ git hash-object tempfile cf4391a3214fce294af57c452668895f993e1f66 $ ls -lh .git/objects/cf/4391a3214fce294af57c452668895f993e1f66 | awk '{print $5}' 4.6K #git gcãã¦ã¿ã $ git gc Counting objects: 18, done. Compressing objects: 100% (13/13), done. Writing objects: 100% (18/18), done. Total 18 (delta 6), reused 0 (delta 0) #.git/objectsã®ä¸ãè¦ã㨠$ find .git/objects .git/objects .git/objects/info .git/objects/info/packs .git/objects/pack .git/objects/pack/pack-bd58b8db3630142ad24e2c79868b3721741cc942.idx .git/objects/pack/pack-bd58b8db3630142ad24e2c79868b3721741cc942.pack
ãã¼ãobjectsããã£ããæ¶ãã¦ãpackãã¡ã¤ã«ãªããã®ãåºæ¥ã¦ãããµã¤ãºè¦ã¦ã¿ãã¨
$ ls -lh .git/objects/pack/pack-bd58b8db3630142ad24e2c79868b3721741cc942.pack | awk '{print $5}' 2.4K
ãªã¼ãã»ã©ãããã¾ã§commitãã¦ãããã¡ã¤ã«ãã¾ãã«packãããããã ã
ãããã£ã¦ãã£ã¹ã¯ã¹ãã¼ã¹ã®ç¡é§é£ããæ¸ããã¦ãã®ãã
ã¡ãªã¿ã«ãpackããç¶æ
ã§pushãããã©ããªããã ããï¼
$ git push origin master #bareãã©ã³ãã®æ¹ãè¦ã«è¡ã£ã¦ã¿ã $ find /var/git/my_repo.git/objects -type f /var/git/my_repo.git/objects/b5/abbe4d64d728c9b9468b515b0df03cebcdad06 /var/git/my_repo.git/objects/47/17b4c5681f5c31e733b36ad571b8c90b62a1e7 (以ä¸çç¥)
ãã£ãã¼ãpackãã¡ã¤ã«ããªããbareã§ã¯å
¨é¨å±éããç¶æ
ã«ãªãã®ãã
ã¡ãªã¿ã«ãããä¸åº¦cloneããªããã¨ãpackãããç¶æ
ã«ãªã£ã¦ãã
ããããpackãã¦éã£ã¦ãã£ã¦ãã¨ãã»ã»ã»ãã¤ã¾ãã大ããªãªãã¸ã§ã¯ãã大éã«ããã¨packã«æéãããã£ã¦ãã¾ãã£ã¦ãã¨ãªã®ããªã
ç¡æå³ã«ãã¤ããªãçªã£è¾¼ãã®ã¯å¾çãããªããªãã