简体   繁体   English

为什么这个git浅克隆比我预期的要大?

[英]Why is this git shallow clone bigger than I expected?

I have a repo that is about 24MB in size but the files in the project are actually just around 2MB. 我有一个大约24MB的repo,但项目中的文件实际上只有2MB左右。 I was under the impression that a shallow clone with --depth 1 would pretty much get me down close to the 2MB of the actual files (sans entire repo). 我的印象是,使用--depth 1的浅层克隆几乎可以让我接近2MB的实际文件(没有整个回购)。

When I do the shallow clone the new repo shows only the current branch but the size is identical (24MB) and looking at the repo with gitx I can see the entire history back to the initial commit. 当我做浅层克隆时,新的repo只显示当前分支但是大小相同(24MB)并且用gitx查看repo我可以看到整个历史记录回到初始提交。

I'd like a way to get just the current state of files (for uploading to a server) without all the history. 我想要一种方法来获取文件的当前状态(用于上传到服务器)而没有所有历史记录。 Am I doing something wrong or just misunderstanding the purpose of the shallow clone? 我做错了什么或只是误解了浅层克隆的目的?

If this is a local clone, then the clone may be operating by hard linking objects in your new repository to those in your old repository (it does this as an optimization on local file systems). 如果这是一个本地克隆,那么克隆可能通过新存储库中的硬链接对象与旧存储库中的对象进行操作(它将此作为本地文件系统上的优化)。 To see if this is the case, you can disable hard linking: 要查看是否是这种情况,您可以禁用硬链接:

git clone --depth 1 --no-hardlinks /path/to/repo.git

If you're just trying to get the current state of files to upload to a server, you should use git archive to generate a ZIP or tar archive of your tree. 如果您只是尝试将当前状态的文件上传到服务器,则应使用git archive生成树的ZIP或tar存档。

I suggest it's because when doing a local clone, git ignores --depth because it favours hardlinks. 我建议这是因为当做一个本地克隆时,git会忽略--depth因为它有利于硬链接。 You can force the behaviour you expected with specifying the source repo with file:///home/user/path/to/repo (ie with the file:/// prefix). 您可以通过file:///home/user/path/to/repo指定源repo来强制执行预期的行为(即使用file:///前缀)。

This is in the docs. 这是在文档中。

As said in the comment, this is strange because generally not reproductible (see this thread ). 正如评论中所说的那样,这很奇怪,因为通常不可再现(见本帖 )。

Example of command that should work: 应该工作的命令示例:

$ git clone --depth 1 git://github.com/rails/rails.git shallow
Initialized empty Git repository in /home/me/shallow/.git/

But anyway, on large repos, the gain achieved with a shallow clone seems not very impressive 但无论如何,在大型回购中,浅层克隆所获得的收益似乎并不令人印象深刻

 git clone --depth 1 repo_url

should do what you want. 应该做你想做的事。

Maybe you put the options after repo url ? 也许你在repo url之后放了选项? On some system they would be ignored. 在某些系统上,它们会被忽略。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM