[英]Remove file from git repository history
我錯誤地檢入(到 github)一些敏感文件。 為了解決這個問題,我按照這里的說明運行了命令:
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch settings.json" --prune-empty --tag-name-filter cat -- --all
echo "settings.json" >> .gitignore
git add .gitignore
git commit -m "Add settings.json to .gitignore"
git push origin --force --all
git push origin --force --tags
git for-each-ref --format="delete %(refname)" refs/original | git update-ref --stdin
git reflog expire --expire=now --all
git gc --prune=now
但是,我可以轉到我的提交歷史記錄以查看已刪除的文件。
要解決此問題,如何從 github 提交歷史記錄中刪除該文件?
嘗試使用最佳實踐是使用新工具git filter-repo
代替 BFG 和git filter-branch
。
注意:如果您在運行上述命令時收到以下錯誤消息:
Error: need a version of `git` whose `diff-tree` command has the `--combined-all-paths` option`
這意味着您必須更新git
。
參見“ 基於路徑的過濾”:
git filter-repo --path settings.json --invert-paths
然后git push --force
最后不需要所有這些 repack/gc/prune:該工具會為您進行清理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.