如何忽略用于git的文件或文件夹历史记录



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

编辑。

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

从工作树和索引

中删除文件

查看使用的命令选项

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

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

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

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

参考:

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-sensive-data-from-a-repository

最新更新