Last active
May 12, 2019 22:10
-
-
Save mwgamera/20fa27f89e9d7e9e7e38d7df81874c1c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Lower size of GIT_DIR with no regard to future performance | |
# klg, Feb 2019 | |
set -e | |
GIT_DIR=$(git rev-parse --git-dir) | |
# objects: prune and repack | |
git prune | |
case "$1" in | |
(-[0-9]) | |
git -c "pack.compression=${1#-}" repack -nadF \ | |
--window 9000 --depth 250 --threads 1 | |
;; | |
(*) | |
git repack -qndl --window 9000 --depth 250 | |
;; | |
esac | |
# refs: pack | |
git pack-refs --all | |
# hooks: remove default samples | |
find "$GIT_DIR" -type f -path '*/hooks/*.sample' -exec rm '{}' + | |
# info: remove unused | |
for f in info/exclude info/attributes | |
do if [ -f "$GIT_DIR/$f" ] | |
then | |
grep -qv '^#' "$GIT_DIR/$f" || rm -f "$GIT_DIR/$f" | |
fi done | |
rm -f "$GIT_DIR/info/refs" # generated by git update-server-info | |
# other fluff | |
rm -rf "$GIT_DIR/logs/" | |
rm -f "$GIT_DIR/gitk.cache" | |
rm -f "$GIT_DIR/COMMIT_EDITMSG" | |
if [ -f "$GIT_DIR/description" ] | |
then | |
grep -qxF "Unnamed repository; edit this file 'description' to name the repository." "$GIT_DIR/description" && | |
rm -f "$GIT_DIR/description" | |
fi | |
# remove empty directories | |
find "$GIT_DIR" -depth -type d -exec rmdir '{}' + 2>/dev/null || : | |
mkdir -p "$GIT_DIR/refs" # this needs to exist even if everything is packed | |
# modules: recurse | |
if [ -d "$GIT_DIR/modules" ] | |
then for module in "$GIT_DIR/modules"/* | |
do | |
( cd "$module" && GIT_DIR=. "$0" "$@" ) | |
done fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment