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

Issue

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.

Answered By – michas

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published