2012-11-13 135 views
2

我只是好奇,因爲我已經注意到,一些庫有自己的分支機構的設置是這樣的:如何在git的另一個分支下創建分支?

git branch -a 

master 
remotes/origin/branch1 
remotes/origin/branch2/lala 
remotes/origin/branch2/yay 
remotes/origin/branch3 
remotes/origin/branch4 

我只是好奇他們是如何做到的分支lala下BRANCH2 yay;或者那不是分支?

任何見解?

回答

7

branch2/lalabranch2/yay分支不是真的「在」分支branch2。每個只是一個正常的分支,其名稱恰好包含/

:; cd /tmp 
:; mkdir gittest 
:; cd gittest 
:; mkdir origin 
:; cd origin 
:; git init 
Initialized empty Git repository in /private/tmp/gittest/origin/.git/ 
:; touch somefile 
:; git add somefile 
:; git commit -m 'initial commit' 
[master (root-commit) 4d62ed7] initial commit 
0 files changed 
create mode 100644 somefile 
:; git branch branch1 
:; git branch branch2/lala 
:; git branch branch2/yay 
:; git branch branch3 
:; git branch branch4 
:; git branch -a 
    branch1 
    branch2/lala 
    branch2/yay 
    branch3 
    branch4 
* master 

:; cd .. 
:; git clone origin local 
Cloning into 'local'... 
done. 
:; cd local 
:; git branch -a 
* master 
    remotes/origin/HEAD -> origin/master 
    remotes/origin/branch1 
    remotes/origin/branch2/lala 
    remotes/origin/branch2/yay 
    remotes/origin/branch3 
    remotes/origin/branch4 
    remotes/origin/master 
+3

這很有道理 - 謝謝。我認爲我困惑的原因是因爲我收到錯誤:'錯誤:無法爲.git/refs/heads/branch1/lala創建目錄致命:無法鎖定ref for update:沒有這樣的文件或目錄' 。我發現我得到這個錯誤是因爲'branch1'已經存在了,它不喜歡我用'/ lala'創建另一個。 – xil3

相關問題