我使用Git和Github(私人账户).
在这个线程上显示类似的东西,但这里是一个旧文件,添加到一个功能分支,该分支合并到一个开发分支,最后合并到master,因为这样做了很多更改.所以它不一样,所需要的是更改历史记录,并隐藏该文件以保护隐私.
Tib*_*ács 25
git建议使用第三方插件git-filter-repo(当git filter-branch命令执行时)。有一长串为什么它比任何其他替代品更好(https://github.com/newren/git-filter-repo#why-filter-repo-instead-of-other-alternatives),我的经验是它非常简单且非常快速。
此命令从所有分支的所有提交中删除文件:
git filter-repo --path <path to the file or directory> --invert-paths
可以使用多个--path参数指定多个路径。您可以在这里找到详细的文档:https :
//www.mankier.com/1/git-filter-repo
hsp*_*her 24
如果您最近提交了该文件,或者该文件在一次或两次提交中已更改,那么我建议您使用rebase并cherrypick删除该特定提交.
否则,您必须重写整个历史记录.
git filter-branch --tree-filter 'rm -f <path_to_file>' HEAD
Run Code Online (Sandbox Code Playgroud)
当您对这些变化感到满意并且确保一切看起来都很好时,您需要更新所有远程分支 -
git push origin --force --all
Run Code Online (Sandbox Code Playgroud)
注意: - 这是一个复杂的操作,你必须知道你在做什么.首先尝试在演示存储库中执行它以查看它是如何工作的.您还需要让其他开发人员了解它,以便它们不会在平均时间内进行任何更改.
小智 24
我找到了这个答案,它有所帮助:
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch path_to_file" HEAD
Run Code Online (Sandbox Code Playgroud)
在这里找到它https://myopswork.com/how-remove-files-completely-from-git-repository-history-47ed3e0c4c35
suh*_*lvs 17
删除文件并从您使用已删除文件完成的提交中重写历史记录(这将从您提交的文件中创建新的提交哈希):
有两种方法:
1.使用过滤器分支
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch <path to the file or directory>' --prune-empty --tag-name-filter cat -- --all
2.使用过滤器回购
pip3 install git-filter-repo
git filter-repo --path <path to the file or directory> --invert-paths
Run Code Online (Sandbox Code Playgroud)
现在强制推送 repo:git push origin --force --all并告诉您的合作者rebase.
van*_*nts 14
我阅读了这篇 GitHub 文章,这使我使用了以下命令(类似于已接受的答案,但更强大):
git filter-branch --force --index-filter "git rm --cached --ignore-unmatch PATH-TO-YOUR-FILE-WITH-SENSITIVE-DATA" --prune-empty --tag-name-filter cat -- --all
Run Code Online (Sandbox Code Playgroud)
首先,将它添加到您的.gitignore文件中,不要忘记提交文件:-)
您可以使用此站点:http : //gitignore.io.gitignore为您生成并添加所需的路径到您的二进制文件/文件夹
添加文件后,.gitignore您可以使用 BFG 删除“旧”二进制文件。
#How to remove big files from the repository
您可以使用git filter-branch或BFG。
https://rtyley.github.io/bfg-repo-cleaner/
###
BFG Repo-Cleanergit-filter-branch 的替代品。
BFG 是 git-filter-branch 的更简单、更快的替代方案,用于清除 Git 存储库历史记录中的不良数据:
*** 删除疯狂的大文件***
- 删除密码、凭据和其他私人数据
在所有这些示例中,bfg 是 java -jar bfg.jar 的别名。
# Delete all files named 'id_rsa' or 'id_dsa' :
bfg --delete-files id_{dsa,rsa} my-repo.git
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11529 次 |
| 最近记录: |