Skip to contentSkip to conversation

Create 'git gc' to perform common maintenance operations.

PATCH In review Shawn O. Pearce 2 participants 2 messages Jun 15, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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
index 91e6966..f92e359 100644
@@ -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
index b8b746f..fb6ba27 100644
@@ -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
new file mode 100644
index 0000000..cb70412
@@ -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
#1 lore raw
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