Is there any difference between git gc
and git repack -ad; git prune
?
If yes, what additional steps will be done by git gc
(or vice versa)?
Which one is better to use in regard to space optimization or safety?
相关问题
- Why does recursive submodule update from github fa
- Extended message for commit via Visual Studio Code
- Emacs shell: save commit message
- Can I organize Git submodules in a flat hierarchy?
- Upload file > 25 MB on Github
相关文章
- 请教Git如何克隆本地库?
- GitHub:Enterprise post-receive hook
- Git Clone Fails: Server Certificate Verification F
- SSIS solution on GIT?
- Is there a version control system abstraction for
- ssh: Could not resolve hostname git: Name or servi
- Cannot commit changes with gitextensions
- git: retry if http request failed
Note that, which
git prune
is run bygit gc
, the former has evolved with Git 2.22 (Q2 2019)"
git prune
" has been taught to take advantage of reachability bitmap when able.See commit cc80c95, commit c2bf473, commit fde67d6, commit d55a30b (14 Feb 2019) by Jeff King (
peff
).(Merged by Junio C Hamano --
gitster
-- in commit f7213a3, 07 Mar 2019)See reachability bitmap here.
git help gc
contains a few hints...I believe those are not done if you only do
git repack -ad; git prune
.The difference is that by default
git gc
is very conservative about what housekeeping tasks are needed. For example, it won't rungit repack
unless the number of loose objects in the repository is above a certain threshold (configurable via thegc.auto
variable). Also,git gc
is going to run more tasks than justgit repack
andgit prune
.According to the documentation,
git gc
runs:git-prune
git-reflog
git-repack
git-rerere
More specifically, by looking at the source code of
gc.c
(lines 338-343)1 we can see that it invokes at the most the following commands:pack-refs --all --prune
reflog expire --all
repack -d -l
prune --expire
worktree prune --expire
rerere gc
Depending on the number of packs (lines 121-126), it may run
repack
with-A
option instead (lines 203-212):Notice on line 211-212 of the
need_for_gc
function that if there aren't enough loose objects in the repository,gc
is not run at all.This is further clarified in the documentation:
As you can see,
git gc
strives to do the right thing based on the state of the repository.In general it's better to run
git gc --auto
simply because it will do the least amount of work necessary to keep the repository in good shape – safely and without wasting too many resources.However, keep in mind that a garbage collection may already be triggered automatically following certain commands, unless this behavior is disabled by the setting the
gc.auto
configuration variable to0
.From the documentation:
So for most repositories you shouldn't need to explicitly run
git gc
all that often, since it will already be taken care of for you.1. As of commit
a0a1831
made on 2016-08-08.