Git 如何处理二进制文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3601672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 08:59:16  来源:igfitidea点击:

How does Git deal with binary files?

gitbinaryfiles

提问by prosseek

  • Do I have to do something to tell Git whether some files are binary (like in Subversion)? Or, can Git handle binary data automatically?
  • If I change the binary file, so that I have 100 binary revisions, will git just store all 100 versions individually in the repository?
  • What are submodules for with git?
  • 我是否必须做一些事情来告诉 Git 某些文件是否是二进制文件(如在 Subversion 中)?或者,Git 可以自动处理二进制数据吗?
  • 如果我更改二进制文件,以便我有 100 个二进制修订版,git 是否会在存储库中单独存储所有 100 个版本?
  • git 的子模块是什么?

采纳答案by Amber

  1. Git can usually detect binary files automatically.
  2. No, Git will attempt to store delta-based changesets if it's less expensive to(not always the case).
  3. Submodules are used if you want to reference other Git repositories within your project.
  1. Git 通常可以自动检测二进制文件。
  2. 不,如果成本较低(并非总是如此),Git 将尝试存储基于增量的变更集。
  3. 如果您想引用项目中的其他 Git 存储库,则使用子模块。

回答by Jason Jenkins

Git uses a heuristic to try to determine if a file is a binary. See this articlefor more information and how to force git to treat a given file as a binary.

Git 使用启发式方法来尝试确定文件是否为二进制文件。有关更多信息以及如何强制 git 将给定文件视为二进制文件,请参阅本文

For good tutorial on submodules see hereand here.

有关子模块的良好教程,请参见此处此处

回答by Alexandre Mazel

I had essentially the same problem: I wanted to git pickle files, which are binary, but git thinks they're text.

我基本上遇到了同样的问题:我想 git pickle 文件,它们是二进制的,但 git 认为它们是文本。

I found this chapter on Git Attributesin the Pro Git Book. So I resolved my issues by creating a .gitattributesfile with this line:

我在 Pro Git Book 中找到了关于 Git 属性的这一章。所以我通过.gitattributes用这一行创建一个文件来解决我的问题:

*.pickle binary

回答by Guillaume Lebourgeois

git add my-binary-file
git commit
git push

Will add your binary file; it is automatic.

将添加您的二进制文件;它是自动的。

Indeed, if you have 100 versions of your file it will store it (but compressed).

事实上,如果您的文件有 100 个版本,它将存储它(但已压缩)。

You can use submodules to make references to other repositories.

您可以使用子模块来引用其他存储库。