Is there a definitive list of commands anywhere that cause git gc --auto
to run? The git-gc(1) man page simply states:
--auto
With this option, git gc checks whether any housekeeping is required; if not, it exits without performing any work. Some git commands run
git gc --auto
after performing operations that could create many loose objects.
(emphasis added)
I'm in the process of organising a large migration from SVN to Git. The overwhelming majority of users will be on Windows PCs, and a not-insignificant portion of them are non-technical. They will be using TortoiseGit (as it closely matches TortoiseSVN, which they are already familiar with) - I've noticed that TortoiseGit does not include any functionality to run git gc
manually at all.
The non-technical staff cannot be expected to have to launch a "git bash" command line to run git gc --auto
from the appropriate working dir; and as we are using the "portable" distribution of MsysGit they will not have the "Git GUI Here.." windows shell context menu shortcut.
Is it reasonable to expect that over time Git will mostly self-maintain, or do I need to try and work out a non-technical user friendly method of invoking git gc --auto
?
Garbage collection is run automatically on several frequently used commands: git pull. git merge. git rebase.
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.
Git prune is used to delete Git objects that the git gc config has judged unreachable.
builtin/merge.c: const char *argv_gc_auto[] = { "gc", "--auto", NULL };
builtin/receive-pack.c: "gc", "--auto", "--quiet", NULL,
git-am.sh: git gc --auto
git-rebase--interactive.sh: git gc --auto &&
git-svn.perl: command_noisy('gc', '--auto');
From git grep -- --auto
on git.git, those results looked interesting. The notable one is builtin/merge.c
meaning that the ever so common git pull
should trigger a git gc --auto
.
Additionally, unless your 'non-technical' staff is doing rather 'advanced' stuff (at which point they wouldn't be 'non-technical' anymore), I don't see why they would ever need to run git gc
manually instead of just letting git gc --auto
handle everything.
With Git 2.17 (Q2 2018), you will have to add git commit
to the list of commands triggering a git gc --auto
.
Actually, that should have been the case since the beginning of Git.
See commit 095c741 (28 Feb 2018) by Ævar Arnfjörð Bjarmason (avar
).
(Merged by Junio C Hamano -- gitster
-- in commit 9bb8eb0, 08 Mar 2018)
commit
: rungit gc --auto
just before thepost-commit
hookChange the behavior of
git-commit
back to what it was back in d4bb43e ("Invoke "git gc --auto
" fromcommit
,merge
,am
andrebase
.", 2007-09-05, Git v1.5.4-rc0) when it wasgit-commit.sh
.Shortly afterwards in f5bbc32 ("Port
git commit
to C.", 2007-11-08, Git v1.5.4-rc0) when it was ported to C, the "git gc --auto
" invocation went away.Since that unintended regression,
git gc --auto
only ran forgit-am
,git-merge
,git-fetch
, andgit-receive-pack
.
It was possible to write a script that would "git commit
" a lot of data locally, andgc
would never run.One such repository that was locally committing generated zone file changes had grown to a size of ~60GB before a daily cronjob was added to "
git gc
", bringing it down to less than 1GB. This will make such cases work without intervention.I think fixing such pathological cases where the repository will grow forever is a worthwhile trade-off for spending a couple of milliseconds calling "
git gc --auto
" (in the common cases where it doesn't do anything).
You can find another illustration of this list with Git 2.27 (Q2 2020), which teach "am
", "commit
", "merge
" and "rebase
", when they are run with the "--quiet
" option, to pass "--quiet
" down to "gc --auto
".
See commit 7c3e9e8, commit 850b6ed (06 May 2020) by Junio C Hamano (gitster
).
(Merged by Junio C Hamano -- gitster
-- in commit 3af459e, 13 May 2020)
auto-gc
: extract a reusable helper from "git fetch
"Reviewed-by: Taylor Blau
Back in 1991006c (
fetch
: convertargv_gc_auto
to structargv_array
, 2014-08-16, Git v2.1.1), we taught "git fetch --quiet
" to pass the "--quiet
" option down to "gc --auto
".This issue, however, is not limited to "fetch":
$ git grep -e 'gc.*--auto' \*.c
finds hits in "
am
", "commit
", "merge
", and "rebase
" and these commands do not pass "--quiet
" down to "gc --auto
" when they themselves are told to be quiet.As a preparatory step, let's introduce a helper function
run_auto_gc()
, that the caller can pass a boolean "quiet
", and redo the fix to "git fetch
" using the helper.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With