Passing a variable to a command in git filter-branch (when reducing repo size by deleting old binaries)

I am exploring ways to reduce repo size by deleting binaries. I am writing a script that will do this for me, based on http://help.github.com/remove-sensitive-data/

It seems that I have work with the solution, but for some reason I cannot pass the parameter to the git nested command. Script with hardcoded file:

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 

it gives me a conclusion

 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 parameterize it as shown below, the whole procedure does not 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 does not delete files.

The question is, how to pass the / escape variable correctly when passing it to a git nested command? (MAC OS x 10.7.2)

+4
source share
1 answer

The problem is the single quotes (') that you use in the git filter. Bash does not replace a variable inside single quotes.

The following should work (unverified):

 fileOLD=selenium-server-standalone-2.16.0.jar git filter-branch --index-filter "git rm --cached --ignore-unmatch /*${fileOLD}" --prune-empty -- --all 
+4
source

Source: https://habr.com/ru/post/1392061/


All Articles