2016-11-04 118 views
0

我知道,通過push-to-empty和clone-mirror,你可以將很多東西推送到新的倉庫,而不僅僅是你的提交。例如,您可以獲得遠程分支複製。但是有什麼方法可以通過遙控器自己傳輸?我可以將遙控器推到遙控器嗎?

特別是在克隆鏡像中,我直觀地認爲它應該是其他存儲庫中所有內容的鏡像。所以我很驚訝,這似乎不包括遙控器。

在下面的例子中,我用兩個遙控器「dest」和「blah」拍攝了一個repo(「repo1」),並將其推送到一個新的裸倉庫「repo2」(push-to-empty)。我也採取了相同的「repo1」並將其克隆到「repo3」。在「repo2」的情況下,沒有任何遙控器或遙控器被推入。在「repo3」的情況下,複製了「dest」遠程的遠程參考(注意:公平,當我推入「repo2」時,該分支不存在,因爲它跟蹤相同),但是沒有跟蹤其他遙控器(「blah」)。

C:\test-remote>mkdir repo1bare 

C:\test-remote>cd repo1bare 

C:\test-remote\repo1bare>git init --bare 
Initialized empty Git repository in C:/test-remote/repo1bare/ 

C:\test-remote\repo1bare>git ls-remote . 

C:\test-remote\repo1bare>cd .. 

C:\test-remote>git clone .\repo1bare .\repo1wd 
Cloning into '.\repo1wd'... 
warning: You appear to have cloned an empty repository. 
done. 

C:\test-remote>cd repo1wd 

C:\test-remote\repo1wd>git remote -v 
origin C:/test-remote/.\repo1bare (fetch) 
origin C:/test-remote/.\repo1bare (push) 

C:\test-remote\repo1wd>copy con dummy.txt 
^Z 
     1 file(s) copied. 

C:\test-remote\repo1wd>git add dummy.txt 

C:\test-remote\repo1wd>git commit -m "dummy" 
[master (root-commit) bf946c1] dummy 
1 file changed, 0 insertions(+), 0 deletions(-) 
create mode 100644 dummy.txt 

C:\test-remote\repo1wd>git push -u origin master 
Counting objects: 3, done. 
Writing objects: 100% (3/3), 211 bytes | 0 bytes/s, done. 
Total 3 (delta 0), reused 0 (delta 0) 
To C:/test-remote/.\repo1bare 
* [new branch]  master -> master 
Branch master set up to track remote branch master from origin. 

C:\test-remote\repo1wd>cd ..\repo1bare 

C:\test-remote\repo1bare>git ls-remote . 
bf946c1f3d14b287b2973fdfcca7379415dbc486  HEAD 
bf946c1f3d14b287b2973fdfcca7379415dbc486  refs/heads/master 

C:\test-remote\repo1bare>git remote -v 

C:\test-remote\repo1bare>git remote add blah http://blah.com/repo1 

C:\test-remote\repo1bare>git remote -v 
blah http://blah.com/repo1 (fetch) 
blah http://blah.com/repo1 (push) 

C:\test-remote\repo1bare>cd .. 

C:\test-remote>mkdir repo2bare 

C:\test-remote\repo1bare>cd repo2bare 

C:\test-remote\repo2bare>git init --bare 
Initialized empty Git repository in C:/test-remote/repo2bare/ 

C:\test-remote\repo2bare>cd ..\repo1bare 

C:\test-remote\repo1bare>git remote add dest C:\test-remote\repo2bare 

C:\test-remote\repo1bare>git remote -v 
blah http://blah.com/repo1 (fetch) 
blah http://blah.com/repo1 (push) 
dest C:\test-remote\repo2bare (fetch) 
dest C:\test-remote\repo2bare (push) 

C:\test-remote\repo1bare>git push --all dest 
Counting objects: 3, done. 
Writing objects: 100% (3/3), 211 bytes | 0 bytes/s, done. 
Total 3 (delta 0), reused 0 (delta 0) 
To C:\test-remote\repo2bare 
* [new branch]  master -> master 

C:\test-remote\repo1bare>cd ..\repo2bare 

C:\test-remote\repo2bare>git remote -v 

C:\test-remote\repo2bare>git ls-remote . 
bf946c1f3d14b287b2973fdfcca7379415dbc486  HEAD 
bf946c1f3d14b287b2973fdfcca7379415dbc486  refs/heads/master 

C:\test-remote\repo2bare>cd .. 

C:\test-remote>git clone .\repo1bare --mirror .\repo3bare 
Cloning into bare repository '.\repo3bare'... 
done. 

C:\test-remote>cd repo3bare 

C:\test-remote\repo3bare>git remote -v 
origin C:/test-remote/.\repo1bare (fetch) 
origin C:/test-remote/.\repo1bare (push) 

C:\test-remote\repo3bare>git ls-remote . 
bf946c1f3d14b287b2973fdfcca7379415dbc486  HEAD 
bf946c1f3d14b287b2973fdfcca7379415dbc486  refs/heads/master 
bf946c1f3d14b287b2973fdfcca7379415dbc486  refs/remotes/dest/master 

C:\test-remote\repo3bare> 
+0

您只能在存儲庫之間推送提交和引用。您不能像配置遙控器列表或掛鉤腳本或其他存儲庫元數據那樣推送配置信息。 – larsks

+0

啊,我沒有意識到這是配置。所以任何遙控器都會出現在'git config --list'中,對嗎?如果我可以識別它們,我可以將它們複製並粘貼到另一個存儲庫的配置中嗎?有沒有辦法只檢索與遙控器相關的配置項目? – Kidburla

回答

2

你可以與你的本地庫這樣的關聯git遙控器列表:

git config --get-regexp '^remote\.' 

將產生類似:

remote.origin.url [email protected]:larsks/oschecks.git 
remote.origin.fetch +refs/heads/*:refs/remotes/origin/* 

,您可以用這些來喂另一端的腳本會將此信息填入git config(然後可能git remote update加載遠程存儲庫的內容)。