Based on this article , I created a small script that should remove all occurrences of a file in whole git repo, all branches, tags and commits. script:
#!/usr/bin/env node var child_process = require('child_process'); if (process.argv.length < 3){ console.error('USAGE: git-forget path/to/file') process.exit(1); } var path = process.argv[2]; var phase = 0; function printLog(error, stdout, stderr) { if (error) { console.error('ERROR' + error); } console.log(++phase); console.log(stdout); } child_process.execSync('git filter-branch --force --index-filter \'git rm -f --cached --ignore-unmatch '+ path +'\' --prune-empty --tag-name-filter cat -- --all'); child_process.execSync('echo "' + path + '" >> .gitignore', printLog); child_process.execSync('git add .gitignore'); child_process.execSync('git commit -m "Add ' + path +' to .gitignore"',printLog) child_process.execSync('git push origin --force --all',printLog); child_process.execSync('git push origin --force --tags',printLog);
This script worked on several repositories (which are private), and on a specific one it kept the original commit of the file that I was trying to delete. After running the script, I did this git log --all -- .npmrc and found the initial commit. What am I missing?
qballer
source share