[英]Clone only if non-empty
Normally, git clone
is happy to clone empty repositories, it just prints the warning 通常,
git clone
很乐意克隆空的存储库,它只是打印警告
warning: You appear to have cloned an empty repository.
警告:您似乎已克隆了一个空的存储库。
Is there any way to tell git to clone only non-empty repositories? 有什么办法告诉git仅克隆非空存储库吗? Ideally, I would prefer
git clone
to simply fail (without creating a working copy) if the repository is empty. 理想情况下,如果存储库为空,我希望
git clone
仅失败(不创建工作副本)。
My current solution is in three steps: (1) clone, (2) see if the clone is empty, (3) delete if it is empty. 我当前的解决方案分为三个步骤:(1)克隆,(2)查看克隆是否为空,(3)删除是否为空。 Does the job but hardly elegant (and it prints warnings that I will need to filter out).
做这项工作,但几乎没有优雅(它会打印警告,我需要过滤掉它)。 Is there a more straightforward solution?
有没有更直接的解决方案?
There is not really a way to do that, but you could approximate it (somewhat poorly): set up a remote pointing to the repo you might clone, and then run git ls-remote
on that remote. 确实没有做到这一点的方法,但是您可以近似(有点差):设置一个指向您可能克隆的仓库的远程指向,然后在该远程上运行
git ls-remote
remote。 (You can do this with any git repository, including a temporary empty one.) If ls-remote finds no refs, cloning that repository would have created an empty repository. (您可以对任何git存储库执行此操作,包括临时的空存储库。)如果ls-remote没有找到引用,则克隆该存储库将创建一个空的存储库。
There are two major defects with this method, and one minor: 这种方法有两个主要缺陷,一个是次要缺陷:
I think you might as well just clone-and-maybe-remove, really. 我认为您真的可以克隆并删除。 (Or just clone and don't remove: there's nothing wrong with an empty repo. I see from a comment that you don't want them; I just don't see the reason why you don't want them. "For automation" is a purpose, but not a reason.)
(或者只是克隆,并且不移除:没有什么错用空的回购协议,我从你不想让他们评论看,我只是不明白为什么你不希望他们的理由“自动化。 “是目的,而不是原因。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.