根据这篇文章,我创建了一个小脚本,旨在删除整个git库中所有分支、标签和提交中文件的所有出现。
#!/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);
这个脚本在一些私有的代码库上运行成功,但是在一个特定的代码库中,它保留了我试图移除的文件的初始提交。运行脚本后,我执行了这个命令git log --all -- .npmrc
并找到了初始提交。我错过了什么吗?