{"thread":{"id":"6121","subject":"[PATCH] Create 'git gc' to perform common maintenance operations.","startedAt":"2006-12-27T07:05:41Z","lastAt":"2006-12-27T07:12:57Z","messageCount":2,"participants":["Shawn O. Pearce","Linus Torvalds"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"30329","messageId":"20061227070541.GA22982@spearce.org","threadId":"6121","inReplyTo":null,"subject":"[PATCH] Create 'git gc' to perform common maintenance operations.","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-12-27T07:05:41Z","receivedAt":"2006-12-27T07:05:41Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Junio asked for a 'git gc' utility which users can execute on a\nregular basis to perform basic repository actions such as:\n\n * prune\n * repack -a -d\n * reflog expire\n * rerere gc\n * pack-refs --prune\n\nSo here is a command which does exactly that.  The parameters fed\nto reflog's expire subcommand can be chosen by the user by setting\nconfiguration options in .git/config (or ~/.gitconfig), as users may\nwant different expiration windows for each repository but shouldn't\nbe bothered to remember what they are all of the time.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n .gitignore               |    1 +\n Documentation/git-gc.txt |   55 ++++++++++++++++++++++++++++++++++++++++++++++\n Makefile                 |    2 +-\n git-gc.sh                |   30 +++++++++++++++++++++++++\n 4 files changed, 87 insertions(+), 1 deletions(-)\n\ndiff --git a/.gitignore b/.gitignore\nindex 91e6966..f92e359 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -41,6 +41,7 @@ git-fmt-merge-msg\n git-for-each-ref\n git-format-patch\n git-fsck-objects\n+git-gc\n git-get-tar-commit-id\n git-grep\n git-hash-object\ndiff --git a/Documentation/git-gc.txt b/Documentation/git-gc.txt\nnew file mode 100644\nindex 0000000..a494b1f\n--- /dev/null\n+++ b/Documentation/git-gc.txt\n@@ -0,0 +1,55 @@\n+git-gc(1)\n+===========\n+\n+NAME\n+----\n+git-gc - Cleanup unnecessary files and optimize the local repository.\n+\n+\n+SYNOPSIS\n+--------\n+'git-gc'\n+\n+DESCRIPTION\n+-----------\n+Runs a number of housekeeping tasks within the current repository,\n+such as compressing file revisions (to reduce disk space and increase\n+performance) and removing unreachable objects which may have been\n+created from prior invocations of gitlink:git-add[1].\n+\n+Users are encouraged to run this task on a regular basis within\n+each repository to maintain good disk space utilization and good\n+operating performance.\n+\n+Configuration\n+-------------\n+\n+The optional configuration variable 'gc.reflogExpire' can be\n+set to indicate how long historical entries within each branch's\n+reflog should remain available in this repository.  The setting is\n+expressed as a length of time, for example '90 days' or '3 months'.\n+It defaults to '90 days'.\n+\n+The optional configuration variable 'gc.reflogExpireUnreachable'\n+can be set to indicate how long historical reflog entries which\n+are not part of the current branch should remain available in\n+this repository.  These types of entries are generally created as\n+a result of using `git commit \\--amend` or `git rebase` and are the\n+commits prior to the amend or rebase occuring.  Since these changes\n+are not part of the current project most users will want to expire\n+them sooner.  This option defaults to '60 days'.\n+\n+See Also\n+--------\n+gitlink:git-prune[1]\n+gitlink:git-repack[1]\n+gitlink:git-rerere[1]\n+\n+Author\n+------\n+Written by Shawn O. Pearce <spearce@spearce.org>\n+\n+GIT\n+---\n+Part of the gitlink:git[7] suite\n+\ndiff --git a/Makefile b/Makefile\nindex b8b746f..fb6ba27 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -157,7 +157,7 @@ BASIC_LDFLAGS =\n SCRIPT_SH = \\\n \tgit-bisect.sh git-checkout.sh \\\n \tgit-clean.sh git-clone.sh git-commit.sh \\\n-\tgit-fetch.sh \\\n+\tgit-fetch.sh git-gc.sh \\\n \tgit-ls-remote.sh \\\n \tgit-merge-one-file.sh git-parse-remote.sh \\\n \tgit-pull.sh git-rebase.sh \\\ndiff --git a/git-gc.sh b/git-gc.sh\nnew file mode 100644\nindex 0000000..cb70412\n--- /dev/null\n+++ b/git-gc.sh\n@@ -0,0 +1,30 @@\n+#!/bin/sh\n+#\n+# Copyright (c) 2006, Shawn O. Pearce\n+#\n+# Cleanup unreachable files and optimize the repository.\n+\n+USAGE=''\n+SUBDIRECTORY_OK=Yes\n+. git-sh-setup\n+\n+reflog_expire=$(git-repo-config gc.reflogExpire)\n+if [ -z \"$reflog_expire\" ]\n+then\n+\treflog_expire=\"90 days\"\n+fi\n+\n+reflog_unreachable=$(git-repo-config gc.reflogExpireUnreachable)\n+if [ -z \"$reflog_unreachable\" ]\n+then\n+\treflog_unreachable=\"60 days\"\n+fi\n+\n+git-pack-refs --prune &&\n+git-reflog expire \\\n+\t--expire=\"$reflog_expire\" \\\n+\t--expire-unreachable=\"$reflog_unreachable\" \\\n+\t--all &&\n+git-prune &&\n+git-repack -a -d &&\n+git-rerere gc || exit\n-- \n1.4.4.3.gd2e4\n"},{"id":"30330","messageId":"Pine.LNX.4.64.0612262312170.4473@woody.osdl.org","threadId":"6121","inReplyTo":"20061227070541.GA22982@spearce.org","subject":"Re: [PATCH] Create 'git gc' to perform common maintenance operations.","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2006-12-27T07:12:57Z","receivedAt":"2006-12-27T07:12:57Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Wed, 27 Dec 2006, Shawn O. Pearce wrote:\n>\n> Junio asked for a 'git gc' utility which users can execute on a\n> regular basis to perform basic repository actions such as:\n> \n>  * prune\n>  * repack -a -d\n\nYou should do \"repack -a -d\" _before_ pruning, because then pruning will \nbe much more efficient (thanks to a more efficient repo format).\n\n\t\tLinus\n"}]}