Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 244
Robby75 Avatar asked May 25 '14 09:05

Robby75


People also ask

What does git gc do?

The git gc command is a repository maintenance command. The "gc" stands for garbage collection. Executing git gc is literally telling Git to clean up the mess it's made in the current repository. Garbage collection is a concept that originates from interpreted programming languages which do dynamic memory allocation.

When should you not run git gc '?

Running git gc manually should only be needed when adding objects to a repository without regularly running such porcelain commands, to do a one-off repository optimization, or e.g. to clean up a suboptimal mass-import.

Does GitHub Run gc?

The git gc command cleans up unnecessary files and optimizes the local repository. GitHub runs this operation on its hosted repositories automatically on a regular basis based on a variety of triggers. Locally you can run it at any time. Running it won't have any adverse effect on your repository.

How do I reduce the size of a .pack file in git?

When you do a Git clone, it will create a copy of the whole repository, this includes the pack file as this is part of the repo too. The only way to reduce the size of the pack file will be by removing contents from your repo.


1 Answers

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.

like image 52
michas Avatar answered Oct 15 '22 07:10

michas