簡體   English   中英

如何使用Git * INTO *裸存儲庫來提取/獲取?

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

我正在編寫一個工具來將我的所有存儲庫從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表示fatal: bad default revision 'HEAD'

我究竟做錯了什么?

免責聲明:
我只有非常非常基本的Git知識(我通常使用Mercurial)。
我正在使用Windows,如果這很重要的話。

嘗試

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

要先將遠程存儲庫備份到裸存儲庫中,請先進行配置

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

然后簡單地運行

git fetch --prune

備份。

  • 您可能可以跳過第一個配置添加,因為在克隆遠程存儲庫時應該已經設置了此配置。
  • 還請注意上面命令中用雙引號括起來( " )以保護星號( * )不被shell解釋。
  • 需要加號以允許非快速更新。 如果您想要備份遙控器的當前狀態,那可能就是您的意圖。
  • 選項--prune也用於刪除現在不存在的分支。

如果你真的想要備份,我想你。 您可以嘗試$ git clone --mirror XXXX命令。 它幾乎可以從存儲庫獲得所有東西。 希望它有所幫助。

$ 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