【发布时间】:2016-03-02 19:03:09
【问题描述】:
基于这个article,我创建了一个小脚本,它应该删除整个git repo、所有分支、标签和提交中所有出现的文件。 脚本:
#!/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);
这个脚本在一些 repos(它们是私有的)上工作,并且在一个特定的 repos 上它保留了对我试图删除的文件的初始提交。脚本运行后,我做了这个git log --all -- .npmrc 并找到了初始提交。我错过了什么?
【问题讨论】:
-
试过bfg,它在本地工作,但不更新远程
-
@qballer,然后将您的更改强制推送到遥控器?
-
@chris nope,它说一切都是最新的。我认为这与关键文件是在初始提交中引入的事实有关。
标签: node.js git git-rewrite-history