当前位置: 代码迷 >> 综合 >> git操作提示 Auto packing the repository for optimum performance. You may also run git gc manually. See
  详细解决方案

git操作提示 Auto packing the repository for optimum performance. You may also run git gc manually. See

热度:88   发布时间:2023-12-18 06:50:56.0

在对git库执行一些操作命令时(比如git am ,git pull,git push等操作)的时候,会出现类似如下提示(我是在用git am打patch时出现的,其他情况也是一回事):

ronny@ronny:~/tmpgitrepol$ git am ~/03patch/kernel/0001-add-kernel-version.patch --keep-cr
Applying: add kernel version for compile
Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 84286, done.

而且git am 后不退出,必须要ctrl+c退出。(其实是git 在将松散对象打包,这个需要时间,没有执行完打包,所以没退出)

里面主要关心如下两句:

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

即表示:

自动包装最佳性能的存储库。
你也可以手动运行 ‘get gc’ 。查看更多信息请执行“git help gc”。


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

原因:

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

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

ronny@ronny:~/tmpgitrepol$ find .git/objects -type f
.git/objects/e4/00a9bf597d6956e6cfc5a4ba57e0f8d78a3025
.git/objects/70/8d7c923cb5954bfe1944e7cf7d7de93298f42f
.git/objects/70/86ddbb3226ad236d3d806cd530006e07392048
.git/objects/bd/b9f69f1b169e6f364455636ef3fb9037f345c5
.git/objects/c4/49782586498f0669271dbb5b2ae92abae7b7cd
.git/objects/4a/4c07ddbe727381f1ee9aab6faa194827419f1b
.git/objects/17/df87cafd85c400b71c7e56ffc2eaa78d2a55d8
.git/objects/ad/f130fd58cd2a0831a47f17e7f14d7ed4d86f9c
.git/objects/97/9c677acf5eb4e45ebe299e8c4b947d899b01af
.git/objects/79/56a405a7bc6e412685a967b3e798445c31bb36
.git/objects/79/12f0ebebb70a675e6ffa57703ddb78bf99d221
.git/objects/4b/ee144e033edd74677a14c311b1eb32b6ef8d6d
.git/objects/4b/1c9b2ce657a6677143b3c08b05379c6b62af05
.git/objects/info/packs
.git/objects/da/3de9a5f2e2d43a9bd53f74368f7e3623d1c1f6
.git/objects/47/b15e4bb0313b9255252c6815bbeb6cf56f9f2c
.git/objects/72/3be48015613503f9c315781b6c7bc60de76c0b
..........................
.git/objects/d6/6bc0f7bd27bf0fc0383792871854c497a01e3d
.git/objects/d6/9a6b3dcb61590a63ca464d69b3613be857936b
.git/objects/pack/pack-862a0b39f354a7fde317459d6dcb8162c865d172.pack
.git/objects/pack/pack-862a0b39f354a7fde317459d6dcb8162c865d172.idx
.git/objects/7f/d654bfdd3255e07154ff3ef8388e295d79e3b0
.git/objects/32/cef5fe936a99b2875942dbbefb93242df454fd
.git/objects/c3/0e9e1875925d71757ffda53b103f99c56d5bda
.git/objects/3f/87d962119364899e0ad111d869f4fb289bad3b
.git/objects/9c/d6bd685d29237f2b82425019dcc549781932a2
.git/objects/95/557cadc1df7bcc8657a842fbf35fb0566d84e9
.git/objects/ee/abfadeea2c0c6467e279d0c8907141e0a27d1c...........................git/objects/d7/f7edb7d654eccd6b7acd0d2e501793bf14e42f
.git/objects/bc/b69da6f5b1294e32deb97046a80dac8b473ddd
.git/objects/73/51b70ef6db6adc61da2c766eb13397b6506152
.git/objects/e2/4d68e5288cfbc200b863c16178f0c32ef5d672
.git/objects/cb/588c96be139adaaaafed4225b16452fc3b69b3
.git/objects/0b/babb1c4e28109bb3cf8e5b9ece5aaeec90d417
.git/objects/28/043911626d5f683938f47477e8680b7d654710
.git/objects/a6/5151506d5821f160bf03e19ec362ba1929a79a
.git/objects/b3/8f35933655073128e9b2a5ebdd6c72d8090811
.git/objects/98/1b94a3bf5ab22f868452d7a1eb5128278ae3d7

然后我们执行git gc试试

git gc
Counting objects: 84389, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (52015/52015), done.
Writing objects: 100% (84389/84389), done.
Total 84389 (delta 31577), reused 84317 (delta 31531)

然后在运行 ’ git gc ’ 命令后,再执行刚才的命令,看下 object 目录里面还剩下多少对象,如下:
ronny@ronny:~/tmpgitrepol$ find .git/objects -type f.git/objects/info/packs
.git/objects/pack/pack-ad6385919cc8c0e4ba2ec4cf7c8e8119a337f625.idx
.git/objects/pack/pack-ad6385919cc8c0e4ba2ec4cf7c8e8119a337f625.pack

接下来再执行git 命令的时候就没有这种情况了,patch直接应用,且不再有上面的提示。
  相关解决方案