gitignore 按文件大小?
我正在尝试实现 Git 来管理创意资产(Photoshop、Illustrator、Maya 等),并且我想根据文件大小而不是扩展名、位置等从 Git 中排除文件。
例如,我不'我不想排除所有 .avi 文件,但随机目录中有一些我不想提交的大量 +1GB avi 文件。
有什么建议吗?
I'm trying to implement Git to manage creative assets (Photoshop, Illustrator, Maya, etc.), and I'd like to exclude files from Git based on file size rather than extension, location, etc.
For example, I don't want to exclude all .avi files, but there are a handful of massive +1GB avi files in random directories that I don't want to commit.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
我是 .gitignore 的新手,因此可能有更好的方法来执行此操作,但我一直使用以下方法按文件大小排除文件:
显然,如果您生成大量大文件,则必须经常运行此代码。
I'm new to .gitignore, so there may be better ways to do this, but I've been excluding files by file size using:
Obviously you'll have to run this code frequently if you're generating a lot of large files.
为了满足 github 的 <100MB 文件限制,请运行以下命令:
To satisfy github's <100MB file limit, run this:
尽管文件大小非常大,但根据:https,只要 @abendine 答案正确,以下内容根本不应该成为问题://stackoverflow.com/a/22057427/6466510
会好得多。也看看这个: find 之间的差异。和 find * in unix 事实证明,将上面的
.
替换为*
可以避免在.git
目录中查找内容。Although the file size is very large and the following should not be an issue at all and provided that @abendine answer is correct, according to: https://stackoverflow.com/a/22057427/6466510
it would be far better. Have a look at this too: Difference between find . and find * in unix it turns out that replacing
.
with*
here above, avoid to find things in.git
directory.我还想提供一个 Windows 版本。
I wanted to also offer a Windows version of this as well.
(2020 年 5 月更新)
微软不久前发布了开源的 Git-LFS。可能这就是大多数人真正在寻找的:
https://git-lfs.github.com/
项目页面的 C&P:
“Git 大文件存储 (LFS) 使用 Git 内的文本指针替换音频样本、视频、数据集和图形等大文件,同时将文件内容存储在 GitHub.com 或 GitHub Enterprise 等远程服务器上。”
(Update 2020-05)
Microsoft released time ago Git-LFS as Open-Source. Probably this is what most people really are searching for:
https://git-lfs.github.com/
C&P from the project page:
"Git Large File Storage (LFS) replaces large files such as audio samples, videos, datasets, and graphics with text pointers inside Git, while storing the file contents on a remote server like GitHub.com or GitHub Enterprise."
我想在所有这些答案中添加一点,您也可以使用 git hook 来获得更自动(或更少人为错误)的东西,如下所示:
cat .git/hooks/pre-commit
这是相当蛮力的,缺点是如果 git hook 添加了新的大文件,原始提交会失败,因为状态(哈希)发生了变化。因此,您需要执行另一次提交来实际提交您已暂存的内容。将此视为一个功能,告诉您检测到新的大文件;-)
I want to add to all these answers that you can also just use a git hook to have something more automatic (or less human-error prone) like this:
cat .git/hooks/pre-commit
It is pretty brute force and the downside is that in case there were new large files added by the git hook, the origin commit fails because the state (hash) changed. So you need to execute another commit to actually commit what you have staged. Consider this as a feature telling you that new large files were detected ;-)
只需添加一个总结有关建议的答案
“删除前导./”
和
“sed 无用”
和
“猫的无用用途”
fwiw我认为猫很好:D
Just adding an answer that summarizes the suggestions about
"remove the leading ./"
and
"useless use of sed"
and
"useless use of cat"
fwiw i think that cat is fine :D
在 python 中尝试这个用户友好的脚本来限制存储库大小,请注意,它将删除 .gitignore 并根据您输入的兆字节数重建它,支持浮点数。
它将自动忽略任何包含
.git
的文件路径。或者,您可以将其设置为特定文件类型,搜索
#specic:
并启用该代码段来执行此操作。仅在 Windows 上测试,在存储库的根目录下创建
Limit Repo Size.cmd
:然后创建
auto-gitignore-limit-repo-file-size。 py
:双击
Limit Repo Size.cmd
(用户友好)示例输出:
Try this user-friendly script in python for limiting the repo size, notice that it will delete the
.gitignore
and rebuild it based on the amount of megabytes you input, supports floats.It will automatically ignore any file path that includes
.git
in it.Optionally, you can set it to a specific file type, search for
#specific:
and enable that piece of code to do that.Only tested on windows, create
Limit Repo Size.cmd
at the root of the repo:and then create
auto-gitignore-limit-repo-file-size.py
:Double click
Limit Repo Size.cmd
(user-friendly)Example output: