从所有的git历史中删除文件
基于这篇文章 ,我创build了一个小脚本,它应该删除整个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);
这个脚本使用了一些repos(私有),并且在一个特定的版本上保留了我试图删除的文件的初始提交。 脚本运行后,我做了这个git log --all -- .npmrc
并find了最初的提交。 我错过了什么?
我觉得发生了什么事是你忘记告诉这个回购的其他用户不要把他们的改变合并到新的历史中,而是要重新定义。 从你引用的文件中:
告诉您的合作者重新分配,而不是合并他们创build的任何分支,这些分支是从旧的(被感染的)存储库历史logging中创build的。 一个合并提交可能会重新引入一些或所有你刚刚进行清除的麻烦历史。
再次尝试运行相同的脚本,看看没有人通过将他/她的本地更改合并到新的头部来重新引入旧的历史logging。
- npm WARN package.json Stock@0.0.1没有版本库字段
- 从Github安装的NPM,含糊不清的说法
- 如何将MEAN Stack部署到Web主机
- AWS Elastic Beanstalk:我是否必须使用完整的“/ node_modules”和“/ bower_components”来部署我的应用程序,并编译sass和其他依赖项?
- 如何启用运行在git-bash v.2.8.2中的nodejs程序中的颜色日志?
- Heroku + Github部署策略
- 未能在git部署节点服务器上推送到heroku
- 使用NodeGit读取Gitconfigurationvariables
- Node.js和项目结构