Create 'git gc' to perform common maintenance operations.
Subsystems (2)
PATCH 1/1 Create 'git gc' to perform common maintenance operations.
Junio asked for a 'git gc' utility which users can execute on a regular basis to perform basic repository actions such as:
* prune
* repack -a -d
* reflog expire
* rerere gc
* pack-refs --prune
So here is a command which does exactly that. The parameters fed to reflog's expire subcommand can be chosen by the user by setting configuration options in .git/config (or ~/.gitconfig), as users may want different expiration windows for each repository but shouldn't be bothered to remember what they are all of the time.
--- .gitignore | 1 + Documentation/git-gc.txt | 55 ++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 2 +- git-gc.sh | 30 +++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 1 deletions(-)
.gitignore +1 -0
@@ -41,6 +41,7 @@ git-fmt-merge-msg git-for-each-ref git-format-patch git-fsck-objects +git-gc git-get-tar-commit-id git-grep git-hash-object
Documentation/git-gc.txt new file +55 -0
55 lines not on this page · raw message
Makefile +1 -1
@@ -157,7 +157,7 @@ BASIC_LDFLAGS = SCRIPT_SH = \ git-bisect.sh git-checkout.sh \ git-clean.sh git-clone.sh git-commit.sh \ - git-fetch.sh \ + git-fetch.sh git-gc.sh \ git-ls-remote.sh \ git-merge-one-file.sh git-parse-remote.sh \ git-pull.sh git-rebase.sh \
git-gc.sh new file +30 -0
@@ -0,0 +1,30 @@ +#!/bin/sh +# +# Copyright (c) 2006, Shawn O. Pearce +# +# Cleanup unreachable files and optimize the repository. + +USAGE='' +SUBDIRECTORY_OK=Yes +. git-sh-setup + +reflog_expire=$(git-repo-config gc.reflogExpire) +if [ -z "$reflog_expire" ] +then + reflog_expire="90 days" +fi + +reflog_unreachable=$(git-repo-config gc.reflogExpireUnreachable) +if [ -z "$reflog_unreachable" ] +then + reflog_unreachable="60 days" +fi + +git-pack-refs --prune && +git-reflog expire \ + --expire="$reflog_expire" \ + --expire-unreachable="$reflog_unreachable" \ + --all && +git-prune && +git-repack -a -d && +git-rerere gc || exit
Signature · 1 line
1.4.4.3.gd2e4
Quoted 6 lines · Shawn O. Pearce
Junio asked for a 'git gc' utility which users can execute on a regular basis to perform basic repository actions such as:
* prune
* repack -a -d
You should do "repack -a -d" _before_ pruning, because then pruning will be much more efficient (thanks to a more efficient repo format).
Linus