1 | #!/bin/sh |
---|
2 | # NB: should support repos checked out with --separate-git-dir! |
---|
3 | # those have .git as a file containing something like |
---|
4 | # gitdir: /path/to/git-dir |
---|
5 | |
---|
6 | if [ ! -d ./.git/ ] ;then |
---|
7 | echo "Not a git repository (./.git/ is not a directory)" |
---|
8 | exit 0 |
---|
9 | fi |
---|
10 | |
---|
11 | echo "> `du -hs ${PWD}/.git/`" |
---|
12 | |
---|
13 | # use a bit of a hack to determine if our stamp exists and is the newest entry in .git |
---|
14 | # (using grep to filter out the . and .. entries) |
---|
15 | LASTFILE="`ls -1tra ./.git/ | grep -v '^\.[\.]*$' | tail -1`" |
---|
16 | if [ "${LASTFILE}" = ".eradicated" ] ;then |
---|
17 | echo "Nothing changed since last `basename $0` - skipping" |
---|
18 | exit 0 |
---|
19 | fi |
---|
20 | |
---|
21 | gfilter () { |
---|
22 | echo git filter-branch -f --index-filter "git rm --force --cached --ignore-unmatch \"$1\"" -- --all |
---|
23 | git filter-branch -f --index-filter "git rm --force --cached --ignore-unmatch \"$1\"" -- --all |
---|
24 | } |
---|
25 | |
---|
26 | for f in $@ ;do |
---|
27 | gfilter "$f" |
---|
28 | done |
---|
29 | |
---|
30 | rm -Rf .git/refs/original && \ |
---|
31 | git reflog expire --expire=now --all && \ |
---|
32 | git gc --aggressive && \ |
---|
33 | git prune |
---|
34 | |
---|
35 | date > .git/.eradicated |
---|
36 | sync ; sleep 1 ; sync ; sleep 1 |
---|
37 | echo "< `du -hs .git/`" | tee -a .git/.eradicated |
---|