首页 > 代码库 > git gc

git gc

有时候当你运行一些git命令(比如git pull)的时候,会有如下提示:

Auto packing the repository for optimum performance. You may alsorun "git gc" manually. See "git help gc" for more information.

  翻译:

自动包装最佳性能的存储库。你也可以手动运行 ‘get gc’ 。有关更多信息,请参见“git帮助gc”。

 

 

当有这个提示的时候,直接运行  ‘ git gc ‘,就可以了

 

原因:

Git 往磁盘保存对象时默认使用的格式叫松散对象 (loose object) 格式。Git 时不时地将这些对象打包至一个叫 packfile 的二进制文件以节省空间并提高效率。当仓库中有太多的松散对象则就会提示你运行 ‘ git gc ‘。

 

我们可以运行 ‘ find .git/objects -type f ‘ 命令,查看一下 objects 目录里有多少对象,如下:

$ find .git/objects -type f.git/objects/07/0cc4950ddcd2595a8134d8e560aef2a733e581.git/objects/13/93d47387301d83214a34883f182cacb717762c.git/objects/1c/1962af2351551af106a46a2bf43543a8bacf52.git/objects/1c/4c0087a2c81ae4d1a521eddcecbbedc5c90270.git/objects/36/39f696bdc97385fefb67926cdc0895e3dc5bb3.git/objects/48/ec12b8a1a0d53d49e80156cfe969e438384da1.git/objects/52/65597ee5edea6bc415506f097ebe072ef79363.git/objects/52/86195cdb9c73333e06fb755272030105c50ef3....git/objects/pack/pack-0c73db178d8a396a3ab624b4acf9dda479593691.idx.git/objects/pack/pack-0c73db178d8a396a3ab624b4acf9dda479593691.pack.git/objects/pack/pack-7c6c1af87ebb721211b490eec0ee6d5b49b5b280.idx.git/objects/pack/pack-7c6c1af87ebb721211b490eec0ee6d5b49b5b280.pack

  然后在运行 ‘ git gc ‘ 命令后,在执行刚才的命令,看下 object 目录里面还剩下多少对象,如下:

$ git gcCounting objects: 11099, done.Delta compression using up to 4 threads.Compressing objects: 100% (3219/3219), done.Writing objects: 100% (11099/11099), done.Total 11099 (delta 7805), reused 10988 (delta 7712)userName@DST56034 /D/gitProject(master)$ find .git/objects -type f.git/objects/info/packs.git/objects/pack/pack-1ddf288322e0efcb6ca533b685b707ef269ff8f0.idx.git/objects/pack/pack-1ddf288322e0efcb6ca533b685b707ef269ff8f0.pack

 

相关文章:http://gitbook.liuhui998.com/4_10.html

git gc