如何忽略git管理的文件或文件夹历史记录?

时间:2019-05-15 13:05:11

标签: git

我的项目中有许多缓存文件可用于单元测试,因此,我的.git文件夹具有3 GB并在不断增加。

编辑。

我不想忽略文件,但是历史记录并不重要,我的目标是减少.git文件夹

2 个答案:

答案 0 :(得分:0)

从工作树和索引中删除文件

View the command options used

git rm -r -n --cached file or directory
git rm -r --cached file
// Add these files or directories to the .gitignore file
// commit and push to warehouse

答案 1 :(得分:0)

您可以在本地存储库中创建一个名为.gitignore的文件,该文件列出了在上载到远程存储库时要忽略的文件,文件类型和路径。

例如,要排除所有以.file结尾的文件,可以添加*.file。如果要排除目录的所有实例,则可以添加folder/

编辑: 如果要从提交历史记录中清除文件,则可以使用git filter-branch命令或BFG Repo-Cleaner,尽管这些工具主要用于隐藏带有敏感信息的文件。

参考文献:

https://git-scm.com/docs/gitignore

https://www.atlassian.com/git/tutorials/saving-changes/gitignore

https://github.com/github/gitignore

从历史记录中清除文件:

https://help.github.com/en/articles/removing-sensitive-data-from-a-repository