Ticket #51158: git-eradicate

File git-eradicate, 1.1 KB (added by RJVB (René Bertin), 8 years ago)
Line 
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
6if [ ! -d ./.git/ ] ;then
7        echo "Not a git repository (./.git/ is not a directory)"
8        exit 0
9fi
10
11echo "> `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)
15LASTFILE="`ls -1tra ./.git/ | grep -v '^\.[\.]*$' | tail -1`"
16if [ "${LASTFILE}" = ".eradicated" ] ;then
17        echo "Nothing changed since last `basename $0` - skipping"
18        exit 0
19fi
20
21gfilter () {
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
26for f in $@ ;do
27        gfilter "$f"
28done
29
30rm -Rf .git/refs/original && \
31    git reflog expire --expire=now --all && \
32    git gc --aggressive && \
33    git prune
34
35date > .git/.eradicated
36sync ; sleep 1 ; sync ; sleep 1
37echo "< `du -hs .git/`" | tee -a .git/.eradicated