我有一个远程裸存储库,其中包含两个分支“master”和“testing”,其中 HEAD 指的是“testing”。克隆此存储库时,git 会检查“master”,如果“master”和“testing”在同一修订版上(即 HEAD == testing == master)。只有当 'testing' 是一个(或多个)提交之后或之前, git clone 才会检查本地端的 'testing' 分支。我在 Mac OS X (10.6.8) 上用 git 1.7.5 试过这个。
附录:我刚刚对非裸存储库进行了同样的尝试:
mkdir A
cd A
git init
touch a
git add a
git commit -m "init repo A with a"
git checkout -b testing
现在回到根目录:
cd ..
git clone A B
cd B
git branch -v -a
* master 28f599b init A
remotes/origin/HEAD -> origin/master
remotes/origin/master 28f599b init A
remotes/origin/testing 28f599b init A
是“主人”!回到 repo A(我们仍在分支“测试”中):
cd ../A
touch b
git add b
git commit -m "add b in branch testing"
现在“测试”是“大师”之前的一次提交。现在让我们再次克隆 A:
cd ..
git clone A C
cd C
git branch -a -v
* testing 23bca39 add b in branch testing
remotes/origin/HEAD -> origin/testing
remotes/origin/master 28f599b init A
remotes/origin/testing 23bca39 add b in branch testing
您可以通过返回 A,签出“master”并将其与“testing”合并来重新验证这种奇怪的行为(这样所有分支都具有相同的头部)。现在将 A 克隆到 D 中,并且 D 将在 master 上签出!