Dựa trên article này, tôi đã tạo một tập lệnh nhỏ để xóa tất cả các lần xuất hiện của một tệp trong toàn bộ git repo, tất cả các nhánh, thẻ và cam kết. Kịch bản:xóa tập tin khỏi tất cả lịch sử 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);
Kịch bản này làm việc trên một vài Repos (mà là tư nhân) và trên một cụ thể nó vẫn giữ được cam kết ban đầu đến tập tin tôi đã cố gắng để loại bỏ. Sau khi kịch bản được chạy, tôi đã làm điều này git log --all -- .npmrc
và tìm thấy cam kết ban đầu. Tôi đang thiếu gì?
sidenote: checkout [BFG, một lựa chọn đơn giản hơn, nhanh hơn cho git-filter-branch] (http://rtyley.github.io/bfg-repo-cleaner) – laggingreflex
đã thử bfg, nó hoạt động cục bộ nhưng không cập nhật từ xa – qballer
@qballer, sau đó buộc đẩy các thay đổi của bạn đến điều khiển từ xa? – Chris