2011-10-25 50 views
9

我正在編寫一個工具來將Bitbucket(支持Git和Mercurial)的所有存儲庫備份到本地計算機。如何使用Git * INTO *裸倉庫進行抽取/提取?

它已經工作了水銀,我在那裏做這樣的:

  • 創建一個新的空倉庫,但不會在本地機器
    (同樣喜歡一個bare Git倉庫)
  • 在工作副本從遠程存儲庫拉到本地空的存儲庫中

現在我正在嘗試使用Git做同樣的事情。

I already found out我不能直接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 logfatal: bad default revision 'HEAD'

我做錯了什麼?

免責聲明:
我只是非常,非常基本的Git知識(我通常使用水銀)。
而且我正在使用Windows,如果這很重要。

+0

[git的日誌,並示出在裸回購]的可能重複(http://stackoverflow.com/questions/6214711/git-log-and-show-on-a-bare-repo) – CharlesB

+0

@CharlesB :這個鏈接中的答案都不適用於我。甚至沒有像'git branch -va'這樣的提示工作,而不是建議的'git log branchname'(我嘗試'master'),也沒有「在存儲庫中可視化所有內容...」命令答案。 –

回答

14

嘗試

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

這似乎只能獲取主分支(我只是用https://github.com/dontangg/nocco試過,因爲Dapper沒有其他分支)。是否可以獲取**所有**分支?這將是一個備份工具,當然我想要備份所有內容。 –

+2

類似於'「*:*」'或'「refs/heads/*:refs/heads/*」'應該這樣做。 –

+0

'*:*'對我來說不起作用('致命的:無效的refspec'*。*''),但是'refs/heads/*:refs/heads/*'這樣做。謝謝! –

3

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

+2

是的,但我希望備份能夠定期運行。因此,在第一次運行後,本地存儲庫已經存在 - >我必須運行'pull' /'fetch' /無論如何,並確保這拉動所有**。 –

+1

當你鏡像你裸露。你可以使用'git fetch --all --progress -v'來更新你的本地bares。 –

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

要備份的遠程倉庫到你的裸庫regulary配置第一

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

,然後只需運行

git fetch --prune 

備份。

  • 您可能會跳過第一次配置添加,因爲在克隆遠程存儲庫時應該已經設置了該配置。
  • 請注意上述命令中的括號雙引號("),以保護asterix(*)不被您的shell解釋。
  • 加號需要允許非快速更新。如果你想備份你的遠程的當前狀態,這可能是你的意圖。
  • 選項--prune也用於刪除現在不存在的分支。
+2

在一個地方很好地解釋了所有相關的事實,特別有用的是關於雙引號和需要在前綴[+ refspec]前加'+(https://git-scm.com/book/en/ V2/GIT中-塔內-THE-的Refspec)。 – starfry