为什么git checkout“origin/branch-name”在git 1.5中导致“no branch”?
问题描述:
这个问题似乎是由于我对git 1.5的经验不足而产生的,因为如果我尝试使用1.7版本的系统,这种方式工作得很好。为什么我最终选择了“无分支”,更重要的是,我能做些什么才能到达“interesting_branch”的头部?为什么git checkout“origin/branch-name”在git 1.5中导致“no branch”?
$ git --version
git version 1.5.6.5
git clone [email protected]:path/to/repo
Initialized empty Git repository in some/local/path/.git
<snip>
cd path
git branch -a
* master
origin/HEAD
origin/develop
origin/feature-cg-interesting_branch
$ git checkout feature-cg-interesting_branch
error: pathspec 'feature-cg-interesting_branch' did not match any file(s) known to git.
$ git checkout -- feature-cg-interesting_branch
error: pathspec 'feature-cg-interesting_branch' did not match any file(s) known to git.
$ git checkout origin/feature-cg-interesting_branch
Note: moving to "origin/feature-cg-interesting_branch" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
git checkout -b <new_branch_name>
HEAD is now at 6534d1d... [Commit message]
$ git branch
* (no branch)
master
答
您需要手动创建本地跟踪分行:
$ git checkout -b feature-cg-interesting_branch origin/feature-cg-interesting_branch
你应该做的每一个遥远而明亮的分支除外master
答
origin/master
不是本地分支,因此它留下你的资料库在分离的头部状态(例如,当您通过其哈希签出标签或提交时)。远程分支可以跟踪上一次与远程存储库同步的每个分支的最后状态。
当您想要进一步开发该分支时,您需要创建本地分支。