git gc

有時候當你運行一些git命令(好比git pull)的時候,會有以下提示:html

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

  翻譯:git

自動包裝最佳性能的存儲庫。
你也能夠手動運行 ‘get gc’ 。有關更多信息,請參見「git幫助gc」。

 

 

當有這個提示的時候,直接運行  ' git gc ',就能夠了性能

 

緣由:ui

Git 往磁盤保存對象時默認使用的格式叫鬆散對象 (loose object) 格式。Git 時不時地將這些對象打包至一個叫 packfile 的二進制文件以節省空間並提升效率。當倉庫中有太多的鬆散對象則就會提示你運行 ' git gc '。spa

 

咱們能夠運行 ' 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 目錄裏面還剩下多少對象,以下:3d

$ git gc
Counting 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.htmlorm

相關文章
相關標籤/搜索