克隆空的、*裸* git 存储库的最直接方法是什么?
我刚刚浏览完 Google 搜索结果,其中包含所有抱怨 git 无法克隆空存储库是多么愚蠢的电子邮件。 一些好心人甚至提交了补丁。 在 git 升级之前,克隆空的、裸露的 git 存储库的最简单、最直接的方法是什么?
理想的解决方案将支持 -o
选项,为远程存储库指定除 origin
之外的名称,并且可以将其实现为简单的 shell 脚本,例如 git-clone-empty-repo
。
(为什么我想这样做:我在我们的 NetApp 文件管理器上设置了一个空的 git 存储库,它将被备份,但我想使用本地硬盘上的克隆并来回推送和拉取与我一起工作的其他人也会做同样的事情,我经常创建新的 git 存储库,而我无法克隆空存储库让我发疯。)
编辑:VonC 的线程表明这
$ git-init
$ git-remote add origin server:/pub/git/test.git
相当于克隆当仓库为空时远程仓库。 这并不完全是我想要的,因为我总是在 git clone 中使用 -o
选项; 我根据远程存储库所在的机器或其他一些令人难忘的标准来命名远程存储库。 (如果它们都被称为origin
,我有太多的存储库来保持它们的正确性。)
编辑:以下答案将被标记为已接受:-)
要克隆一个空的, path 处的裸存储库,
- 在
~/git/onefile
保留一个包含一个无害文件(例如.gitignore
)的非裸 git 存储库。 (或者,动态创建这样的存储库。) (cd ~/git/onefile; git push
pathmaster)
git clone - o
name path
换句话说,不要尝试克隆空存储库,而是在创建它之后,向其推送一个包含一个无害的简单存储库文件。 那么它就不再是空的并且可以被克隆。
如果有人没有打败我,我将发布一个 shell 脚本。
I've just finished cruising the Google search results that contain all the email rants about how stupid it is that git can't clone an empty repository. Some kind soul even submitted a patch. Until git is upgraded, what is the simplest, most straightforward method to clone an empty, bare git repository?
The ideal solution will support the -o
option to give the remote repo a name other than origin
, and it will be implementable as a simple shell script, e.g., git-clone-empty-repo
.
(Why I want to do this: I've set up a bare, empty git repo on our NetApp filer where it will be backed up, but I want to work with a clone on my local hard drive and push and pull back and forth. Other people I work with will be doing the same. I create new git repos a lot and my inability to clone an empty repo makes me crazy.)
EDIT: VonC's thread suggests that
$ git-init
$ git-remote add origin server:/pub/git/test.git
is equivalent to cloning the remote repo when the repo is empty. This is not quite what I want because I always use the -o
option with git clone; I name the remote repo according to what machine it is on or some other memorable criterion. (I have too many repos to keep them straight if they're all called origin
.)
EDIT: The following answer will be marked accepted :-)
To clone an empty, bare repo at path,
- Keep at
~/git/onefile
a non-bare git repo containing one innocuous file such as.gitignore
. (Alternatively, create such a repo dynamically.) (cd ~/git/onefile; git push
pathmaster)
git clone -o
name path
In other words, don't attempt to clone the empty repo, but rather after creating it, push to it a simple repo containing one innocuous file. Then it is no longer empty and can be cloned.
If someone does not beat me to it, I will post a shell script.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能只有一个 git 存储库,其中包含最少数量的文件:
一个:
.gitignore
,其中有明显的忽略模式。然后克隆那个“几乎空”的存储库。
请注意,这样一个“几乎为空”的存储库(“几乎”是因为它在 .git 目录旁边仍然有一个最小的工作目录)可以通过“
git clone --bare
”(如 此处说明),使其成为一个真正的裸仓库(但是不是一个“空”)。这就是您可以克隆的裸存储库:
您在
Junio C Hamano 对此回应:
May be just have a git repo with the minimum number of file in it:
one:
.gitignore
with obvious ignore patterns in it.And then clone that "almost empty" repository.
Note that such an "almost empty" repository ("almost" because it still has a minimal working directory alongside the .git directory) can then by '
git clone --bare
' (as illustrated here), making it a true bare repo (but not an "empty" one).This is that bare repo you can then:
You have in this thread a good summary of the "other way around" (which I keep here for reference).
To which Junio C Hamano responded: