18

The last few days, each and every push to our git repository has caused auto-packing on the server.

The output on the client when this happens:

~pdr git:master ❯❯❯ git push origin master
Counting objects: 44, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (26/26), done.
Writing objects: 100% (27/27), 4.67 KiB, done.
Total 27 (delta 14), reused 0 (delta 0)
Auto packing the repository for optimum performance.

The packing happens on the server, and ps shows these git commands at work:

git      23252  0.0  0.0  68520   552 ?        S    15:21   0:00 sshd: git@notty  
git      23253  0.0  0.0   9660   540 ?        Ss   15:21   0:00 git shell -c git-receive-pack 'repositories/pdr.git'
git      23254  0.0  0.0  16644  2136 ?        S    15:21   0:00 git receive-pack repositories/pdr.git
git      23258  0.0  0.0   9660   624 ?        S    15:21   0:00 git gc --auto --quiet
git      23261  0.0  0.0   9660   504 ?        S    15:21   0:00 git repack -d -l -q -A
git      23262  0.0  0.0   4104   376 ?        S    15:21   0:00 /bin/sh /usr/lib/git-core/git-repack -d -l -q -A
git      23275  267 92.2 9569724 3742468 ?     Sl   15:21  23:07 git pack-objects --keep-true-parents --honor-pack-keep --non-empty --all --reflog --unpack-unreachable --local -q --delta-base-offset /home/git/repositories/pdr.git/objects/.tmp-23262-pack

I have run a manual "git gc" followed by a "git fsck" on the server. No error messages, but on the next push it started auto-packing again.

This is on a server running Ubuntu Server 10.04 LTS with Git 1.7.0.4.

anr78
  • 1,308
  • 2
  • 17
  • 31
  • 2
    I recon the question is: "Why?" – drvdijk Jul 29 '13 at 13:34
  • 1
    possible duplicate of [what does "Auto packing the repository for optimum performance mean"?](http://stackoverflow.com/questions/8633981/what-does-auto-packing-the-repository-for-optimum-performance-mean) – drvdijk Jul 29 '13 at 13:35
  • Check out http://stackoverflow.com/questions/7392155/why-does-git-run-git-gc-auto-on-every-merge. This may be a duplicate of that, in fact. – pattivacek Jul 29 '13 at 13:36
  • 1
    @drvdijk "why is this happening on every push" is not the same as "what does auto packing a repo mean". – AD7six Jul 29 '13 at 14:10
  • The question is indeed "Why?" :) – anr78 Jul 29 '13 at 16:57
  • @patrickvacek I am not running on windows, and none of the commands have given any error commands. Not on client, not on server. – anr78 Jul 29 '13 at 17:00
  • @drvdijk The OP in the post you link to never replied, so I don't know what his issue was. I have let all gc/repack commands complete, and it still triggers on every push. – anr78 Jul 29 '13 at 17:04

1 Answers1

31

Git decides whether to auto gc based on two criteria:

  1. Are there too many packs? (Literally, are there more than 50 files with .idx in .git/objects/pack?)
  2. Are there too many loose objects? (Literally, are there more than 27 files in .git/objects/17?)

If for some reason Git is not able to merge the pack files or remove the loose objects in that directory, it will think it needs to auto-gc again next time.

I would check the contents of the two directories cited above to see if the (default) criteria are met and see if the criteria change after the re-packing.

Some reasons for failure to complete the process might be:

  • some sort of permissions problem
  • unreachable objects that are ignored by Git's garbage collection or not pruned by default due to their youth
  • insufficient disk space to complete the gc (the repack)
  • insufficient memory to complete the gc (the repack)
  • objects too large to fit in a specified pack size (see git config pack.packSizeLimit which defaults to unlimited but may be overridden by the user)

You should also ensure of course that the gc related tunable parameters haven't been set unreasonably by looking at:

git config -l | grep gc

For some other details, see the Git SCM book on Git Internals.

Emil Sit
  • 22,894
  • 7
  • 53
  • 75
  • There are no loose objects, but there are 346 packs... No gc options have been set, but because of a puny server with 4GB ram we have set pack.windowmemory=50m and pack.packsizelimit=100m. And we have a huge repo because we did the mistake of adding big binary files when we started out with git. – anr78 Jul 30 '13 at 05:34
  • 1
    "Unreasonable tuning parameters" was indeed the problem. I increased pack.packsizelimit to 500m, and after a repack I have 27 .idx files in objects/pack and the the repo behaves. Thanks for helping. – anr78 Jul 30 '13 at 08:10
  • packSizeLimit was set to 10m for me. Changing it to 2g resolved this issue. Thanks. – d4ryl3 Jul 19 '16 at 04:13
  • 1
    For anyone with too many loose objects: Use `git gc --prune=3days` to remove them for everything older than 3 days. (Default is 2 weeks otherwise.) – Kissaki Jul 24 '19 at 13:12