简体   繁体   English

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

[英]How do I pull/fetch with Git *INTO* a bare repository?

I'm writing a tool to backup all my repositories from Bitbucket (which supports Git and Mercurial) to my local machine. 我正在编写一个工具来将我的所有存储库从Bitbucket (支持Git和Mercurial)备份到我的本地计算机。

It already works for Mercurial, where I do it like this: 它已经适用于Mercurial,我这样做:

  • create a new empty repository without a working copy on the local machine 在本地计算机上创建一个没有工作副本的新空存储库
    (the same like a bare Git repository) (就像一个bare Git存储库)
  • pull from the remote repository into the local empty repository 从远程存储库拉入本地空存储库

Now I'm trying to do the same with Git. 现在我正在尝试用Git做同样的事情。

I already found out that I can't directly pull to a bare repository and that I should use fetch instead. 已经发现我不能直接pull一个裸存储库,而是我应该使用fetch

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 确实取了一些东西,但之后本地存储库是空的。
( git log says fatal: bad default revision 'HEAD' ) git log表示fatal: bad default revision 'HEAD'

What am I doing wrong? 我究竟做错了什么?

Disclaimer: 免责声明:
I have only very, very basic Git knowledge (I usually use Mercurial). 我只有非常非常基本的Git知识(我通常使用Mercurial)。
And I'm using Windows, if that matters. 我正在使用Windows,如果这很重要的话。

尝试

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

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. 还请注意上面命令中用双引号括起来( " )以保护星号( * )不被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. 选项--prune也用于删除现在不存在的分支。

I think you if you really want to backup. 如果你真的想要备份,我想你。 You can try $ git clone --mirror XXXX command. 您可以尝试$ git clone --mirror XXXX命令。 it will get almost everything from repository. 它几乎可以从存储库获得所有东西。 Hope it is helpful. 希望它有所帮助。

$ git fetch https://github.com/SamSaffron/dapper-dot-net.git +refs/heads/*:refs/heads/* --prune

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

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