如何使用 Git *INTO* 拉取/获取裸存储库?

发布于 2024-12-12 02:13:05 字数 1147 浏览 0 评论 0原文

我正在编写一个工具来将我的所有存储库从 Bitbucket (支持 Git 和 Mercurial)备份到我的本地计算机。

它已经适用于 Mercurial,我这样做:

  • 在本地计算机上创建一个没有工作副本的新空存储库
    (与 bare Git 存储库相同)
  • 从远程存储库拉入本地空存储库

现在我尝试使用 Git 执行相同的操作。

已经发现我不能直接pull 到一个裸存储库,我应该使用 fetch 代替。

所以我尝试了一下:

C:\test>git fetch https://github.com/SamSaffron/dapper-dot-net.git
remote: Counting objects: 1255, done.
remote: Compressing objects: 100% (1178/1178), done.
remote: Total 1255 (delta 593), reused 717 (delta 56)
Receiving objects: 100% (1255/1255), 13.66 MiB | 706 KiB/s, done.
Resolving deltas: 100% (593/593), done.
From https://github.com/SamSaffron/dapper-dot-net
 * branch            HEAD       -> FETCH_HEAD

显然 Git 确实获取了一些东西,但之后本地存储库是空的。
git log致命:错误的默认修订版“HEAD”

我做错了什么?

免责声明:
我只有非常非常基本的 Git 知识(我通常使用 Mercurial)。
我正在使用 Windows,如果这很重要的话。

I'm writing a tool to backup all my repositories from Bitbucket (which supports Git and Mercurial) to my local machine.

It already works for Mercurial, where I do it like this:

  • create a new empty repository without a working copy on the local machine
    (the same like a bare Git repository)
  • pull from the remote repository into the local empty repository

Now I'm trying to do the same with Git.

I already found out that I can't directly pull to a bare repository and that I should use fetch instead.

So I tried it:

C:\test>git fetch https://github.com/SamSaffron/dapper-dot-net.git
remote: Counting objects: 1255, done.
remote: Compressing objects: 100% (1178/1178), done.
remote: Total 1255 (delta 593), reused 717 (delta 56)
Receiving objects: 100% (1255/1255), 13.66 MiB | 706 KiB/s, done.
Resolving deltas: 100% (593/593), done.
From https://github.com/SamSaffron/dapper-dot-net
 * branch            HEAD       -> FETCH_HEAD

Obviously Git did fetch something, but the local repository is empty after that.
(git log says fatal: bad default revision 'HEAD')

What am I doing wrong?

Disclaimer:
I have only very, very basic Git knowledge (I usually use Mercurial).
And I'm using Windows, if that matters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

甜味超标? 2024-12-19 02:13:06

尝试

git fetch https://github.com/SamSaffron/dapper-dot-net.git master:master

Try

git fetch https://github.com/SamSaffron/dapper-dot-net.git master:master
你げ笑在眉眼 2024-12-19 02:13:06

要将远程存储库备份到裸存储库中,请先定期配置

git config remote.origin.url https://github.com/SamSaffron/dapper-dot-net.git
git config remote.origin.fetch "+*:*"

,然后只需运行

git fetch --prune

备份即可。

  • 您可能可以跳过第一个配置添加,因为这应该在克隆远程存储库时已经设置。
  • 另请注意上述命令中的双引号 ("),以保护星号 (*) 不被您的 shell 解释。
  • 需要加号允许非快进更新。如果您想备份远程的当前状态,这可能是您的意图,
  • 也可以删除现在不存在的分支。

To backup the remote repository into your bare repository regulary configure first

git config remote.origin.url https://github.com/SamSaffron/dapper-dot-net.git
git config remote.origin.fetch "+*:*"

and then simply run

git fetch --prune

to backup.

  • You probably can skip the fist configuration addition as this should has been already set while cloning the remote repository.
  • Please also mind the enclosing double quotation marks (") in the above command to protect the asterix (*) not to be interpreted from your shell.
  • The plus sign is needed to allow non-fastforward updates. That is probably your intention if you want to backup the current state of your remote.
  • Option --prune is used to also delete by now non-existent branches.
我们的影子 2024-12-19 02:13:06

我想如果你真的想备份的话。您可以尝试 $ git clone --mirror XXXX 命令。它将从存储库中获取几乎所有内容。希望它有帮助。

I think you if you really want to backup. You can try $ git clone --mirror XXXX command. it will get almost everything from repository. Hope it is helpful.

不语却知心 2024-12-19 02:13:06
$ git fetch https://github.com/SamSaffron/dapper-dot-net.git +refs/heads/*:refs/heads/* --prune
$ git fetch https://github.com/SamSaffron/dapper-dot-net.git +refs/heads/*:refs/heads/* --prune
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文