I am looking into ways of reducing repo size by removing binary files. I am writing script that will do this for me, based on http://help.github.com/remove-sensitive-data/
It seems that I have solution working, but somehow I can’t pass parameter into nested git command.
Script with hardcoded file works:
git filter-branch --index-filter 'git rm --cached --ignore-unmatch /*selenium-server-standalone-2.16.0.jar' --prune-empty -- --all
git push origin master --force
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
git status
git pull
this gives me output
Rewrite f9a33e41dd6da4630773272ec18d194d14935a83 (10/10)rm 'bin/selenium-server-standalone-2.16.0.jar'
rm 'selenium-server-standalone-2.16.0.jar'
Ref 'refs/heads/master' was rewritten
Ref 'refs/remotes/origin/master' was rewritten
WARNING: Ref 'refs/remotes/origin/master' is unchanged
but when I try to parametrize this, like below, whole procedure doesn’t work
fileOLD=selenium-server-standalone-2.16.0.jar
git filter-branch --index-filter 'git rm --cached --ignore-unmatch /*${fileOLD}' --prune-empty -- --all
git push origin master --force
rm -rf .git/refs/original/
git reflog expire --expire=now --all
git gc --prune=now
git gc --aggressive --prune=now
git status
git pull
output
Rewrite 0491bf3461726c2ebd595ebc480010b5bf722302 (1/10)fatal: '/About Administration Tools.app' is outside repository
index filter failed: git rm --cached --ignore-unmatch /*${fileOLD}
and it doesn’t remove files.
The question is how do I correctly pass/escape variable when passing it into nested git command? (MAC OS x 10.7.2)
The problem are the single quotes (‘) you use in the git filter. Bash will not replace the variable inside single quotes.
The following should work (untested):