Search code examples
gitgarbage-collection

Does "git gc" also run "git repack"?


I have turned off git's annoying automatic repacking functionality (I guess that most git-users know the "repacking for optimal performance" message when working with git) and am instead invoking "git gc" overnight with a cronjob.

However I am unsure if that is enough and whether I should also run "git repack" before or after "git gc".

The manpages of "git repack" and "git gc" don't mention any connection between the two, and the manpage of "git repack" actually contains this phrase:

Instead, the loose unreachable objects will be pruned according to normal expiry rules with the next git gc invocation.

This would indicate to me that "git gc" is not sufficient for all house-keeping tasks and "git repack" is also needed. Is that correct and what housekeeping-commands should be used for git?


Solution

  • git repack just repacks the objects.

    git gc repacks them and throws away the old unreachable objects.

    To verify you can do something like find .git/objects before and after git gc: before you should see all new objects as separate files. Afterwards there should be only one big pack file.

    For details you can also have a look at the code: In builtin/gc.c the repack command is prepared and executed.