如何处理 Git 存储库中的图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5756324/
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
How do I handle images in a Git repo?
提问by dugla
I have inherited a medium sized iOS project - ~30,000 lines of code - that has an insanenumber of image assets. Of course we use Git/Github to scm. Currently the images are included in the directory tree and thus gets ingested into the repo, bloating the heck out of it and generally making development a big headache.
我继承了一个中等规模的 iOS 项目 - 大约 30,000 行代码 - 拥有数量惊人的图像资产。当然我们使用Git/Github来scm。目前,这些图像包含在目录树中,因此被摄取到 repo 中,使它变得臃肿并且通常使开发成为一个大问题。
We have 4 devs on the project, some virtual. It occurs to me to move the images to Dropbox, refer to them from the iOS project and keep things ship shape.
我们有 4 个项目开发人员,其中一些是虚拟的。我突然想到将图像移动到 Dropbox,从 iOS 项目中引用它们并保持状态。
Does anyone have a comment on this idea? What do you do do deal with image/video/audio files in a Git scm setup?
有人对这个想法有意见吗?你如何处理 Git scm 设置中的图像/视频/音频文件?
采纳答案by Ernest Friedman-Hill
I'd be pretty nervous about that, actually; what if you want to update an image, then change your mind? Or what if you need to build a maintenance release with old images?
实际上,我对此会非常紧张;如果您想更新图像,然后改变主意怎么办?或者如果您需要使用旧图像构建维护版本怎么办?
If this is really a problem -- and I've never seen this actually be a problem in practice, but I'll take your word for it -- why not just use one repo for the images, another for everything else? You can then just be lazy about syncing the image one.
如果这真的是一个问题——我从来没有在实践中看到这真的是一个问题,但我会相信你的话——为什么不只使用一个存储库来存储图像,另一个用于其他一切?然后,您可以懒惰地同步图像。
回答by Brian Campbell
It can be a bit of a pain to deal with, but what I've used in the past are submodulesfor images and media. That way, you can pull down just your code without getting the images if you want to, but you can still keep your images and media in sync with your code. When the submodule history would get too big, we could just create a new repo without the history, and swap out the old submodule for the new one. That way, people could be in sync with the latest version of the media, without having to pull the full history.
处理起来可能有点痛苦,但我过去使用的是图像和媒体的子模块。这样,如果需要,您可以只下拉代码而不获取图像,但您仍然可以使图像和媒体与代码同步。当子模块历史变得太大时,我们可以创建一个没有历史的新仓库,然后将旧的子模块换成新的。这样,人们就可以与最新版本的媒体保持同步,而无需提取完整的历史记录。
We would frequently start out with green screens of our video in the submodule, so we could develop with the video before it was in its final form, but once it was composited, we would break the submodule history and push out a new submodule that had just the composited videos. That avoided having an entire extra copy of every video, while still allowing you (with a little manual work of swapping the submodules around) to get the old version out if you needed to.
我们会经常从子模块中视频的绿屏开始,因此我们可以在视频处于最终形式之前对其进行开发,但是一旦合成,我们将打破子模块历史并推出一个新的子模块只是合成视频。这避免了每个视频的完整额外副本,同时仍然允许您(通过一些手动交换子模块的工作)在需要时取出旧版本。
Submodules will increase the amount of work that you will need to do. If you want to commit changes to your images, you need to change them in the submodule, commit that, push it, then go to the parent project, commit the change to the submodule, and push that. For simple cases you can write some scripts to make this a little easier, but in more complicated cases like merge conflicts it will be considerably more complicated than using a single project for everything.
子模块将增加您需要做的工作量。如果要提交对图像的更改,则需要在子模块中更改它们,提交并推送它,然后转到父项目,将更改提交到子模块,然后推送它。对于简单的情况,您可以编写一些脚本来使这更容易一些,但在更复杂的情况下,例如合并冲突,它会比对所有内容使用单个项目复杂得多。
回答by MatrixFrog
I haven't used it myself, but there is a project called git mediawhich is designed to make it easier to work with big binary files like images in git. It's from Scott Chacon who's kind of a big deal in the git world, so I imagine it probably works quite well.
我自己没有使用过它,但有一个名为git media的项目,它旨在使在 git 中处理大型二进制文件(如图像)更容易。它来自 Scott Chacon,他在 git 世界中是个大人物,所以我想它可能运行得很好。
回答by StriplingWarrior
git-lfs
appears to be a good modern solution to this problem. It tracks files as local text pointers in your repo, while storing them on an external large file store. This is kind of like the subrepo solution, but without the need for as much manual intervention.
git-lfs
似乎是解决这个问题的一个很好的现代解决方案。它在您的存储库中将文件作为本地文本指针进行跟踪,同时将它们存储在外部大文件存储中。这有点像 subrepo 解决方案,但不需要太多的手动干预。
On the one hand, this makes you more dependent on having internet access--you probably won't be able to switch between branches as fully if you can't access the external file store. On the other hand, it means that you're not downloading the entire history of every binary file when you clone a repo.
一方面,这让您更加依赖互联网访问——如果您无法访问外部文件存储,您可能无法在分支之间完全切换。另一方面,这意味着您在克隆存储库时不会下载每个二进制文件的完整历史记录。
It's supported by GitHub, Visual Studio Online, and Bitbucket Server.
回答by Blake Taylor
I find git to be the wrong tool for the job when it comes to dealing with binary source.
我发现 git 是处理二进制源代码的错误工具。
Finalized assets that your software requires inorder to be considered "complete" would be best kept committed in your repo but I would seek out an alternative solution for working with actual image source such as an ai file or psd.
您的软件需要被视为“完整”的最终资产最好保留在您的存储库中,但我会寻找一种替代解决方案来处理实际图像源,例如 ai 文件或 psd。
Git offers little if any benefit for working with these files and as you stated, it bloats the repo which negatively effects areas where git offers actual benefit.
Git 对处理这些文件几乎没有任何好处,而且正如您所说,它会使 repo 膨胀,从而对 git 提供实际好处的区域产生负面影响。
I myself have considered dropbox, but I feel the need for a more tailored solution. One that allows me to quickly sync across computers, automatically stores that last ten versions or so, allows me to preserve and name specific versions and supports locking of files (Read: avoid need to try and merge binary files.) This is a different tool for a different job/workflow. Sadly I know not of it's existence, but I would love to see it come to be.
我自己也考虑过 Dropbox,但我觉得需要一个更量身定制的解决方案。允许我在计算机之间快速同步,自动存储最近十个左右的版本,允许我保留和命名特定版本并支持文件锁定(阅读:避免需要尝试合并二进制文件。)这是一个不同的工具对于不同的工作/工作流程。可悲的是,我不知道它的存在,但我很想看到它成为现实。
回答by user2520657
I have been interested in this issue. In my meanderings I came across git annex: http://git-annex.branchable.comHaven't used it because my server provider doesn't have it installed.
我对这个问题很感兴趣。在我的曲折中,我遇到了 git 附件:http: //git-annex.branchable.com没有使用它,因为我的服务器提供商没有安装它。
回答by Shahadat Hossain
You can store the image and binaries using Subversion system (SVN). The images and other binaries are not going to change very often, but still you can get notified when those files are changed or updated centrally.
您可以使用 Subversion 系统 (SVN) 存储图像和二进制文件。图像和其他二进制文件不会经常更改,但是当这些文件发生更改或集中更新时,您仍然可以收到通知。
Git is best for version-ing only source code and only include source codes in Github.
Git 最适合仅对源代码进行版本控制,并且只在 Github 中包含源代码。
Subversion and Git both together can give you total versioning of all things.
Subversion 和 Git 一起可以为您提供所有事物的总版本控制。