克隆空的、*裸* git 存储库的最直接方法是什么?

发布于 2024-07-22 05:13:56 字数 1165 浏览 6 评论 0原文

我刚刚浏览完 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 处的裸存储库,

  1. ~/git/onefile 保留一个包含一个无害文件(例如 .gitignore)的非裸 git 存储库。 (或者,动态创建这样的存储库。)
  2. (cd ~/git/onefile; git push path master)
  3. 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,

  1. Keep at ~/git/onefile a non-bare git repo containing one innocuous file such as .gitignore. (Alternatively, create such a repo dynamically.)
  2. (cd ~/git/onefile; git push path master)
  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红墙和绿瓦 2024-07-29 05:13:56

可能只有一个 git 存储库,其中包含最少数量的文件:

一个:.gitignore,其中有明显的忽略模式。

然后克隆那个“几乎空”的存储库。
请注意,这样一个“几乎为空”的存储库(“几乎”是因为它在 .git 目录旁边仍然有一个最小的工作目录)可以通过“git clone --bare”(如 此处说明),使其成为一个真正的裸仓库(但是不是一个“空”)。
这就是您可以克隆的裸存储库:

  • 克隆到您想要的任何地方。
  • 或者(更重要的是)推送到(因为它是一个裸仓库)

您在

$ git-init
$ git-remote add origin server:/pub/git/test.git

对于一个新项目(还没有代码),我想制作一个空的、裸露的
远程公共服务器上的存储库(无工作副本)作为起始
点,克隆到本地,逐步在本地创建内容并
将其推送到远程公共服务器。

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:

  • clone everywhere you want.
  • or (more importantly) push to (since it is a bare repo)

You have in this thread a good summary of the "other way around" (which I keep here for reference).

$ git-init
$ git-remote add origin server:/pub/git/test.git

For a new project (no code yet) I wanted to make an empty, bare
repository (no working copy) on a remote public server as a starting
point, clone it locally, and gradually create content locally and
push it out to the remote, public server.

To which Junio C Hamano responded:

You prepared an empty bare repository for publishing, and that
is very good.

The next step is that you prepare your contents elsewhere. That
would be your private working place, i.e. the place you would
normally work in).
You push from your private working place
into that publishing repository.
Your working place is where
the very initial commit should come from, since you are the one
who is starting the project.

Note that the private working place does not have to be a clone
of the empty one. That actually is backwards. Your work
started from your private working place to the publishing one.

You could even clone your private repository to publishing one
to make it clear who is the master and who is the copy if you
wanted to, but because you already have the bare repository for
publishing, just pushing into it is all that is needed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文