开发者

Git updates submodule with an unamed branch

I've used git for quite a bit now but stayed away from submodules since I didn't had a good reason to use them. However, recently I began a project which clearly needs to use this feature of git.

However, each time I clone the entire project the submodule ends in a branch with no name. Here are the commands I execute:

git clone <url to project>
开发者_C百科git submodule update --init <submodule>
cd <submodule>; git branch

and it prints out:

* (no branch)
  master

I need to do an additional

git checkout master

Now my question is: is this the standard behavior? If not, can you help me out understanding what I'm doing wrong?

Thanks


Unlike some other SCMs, commits in Git do not inherently belong to any particular branch. A branch head is like a bookmark for a commit. When you have a branch checked out (i.e. the file .git/HEAD contains a reference to the branch), and you make a commit, Git moves that bookmark forward to point to the new commit.

But this tracking behaviour doesn't apply here. As you may already know, a submodule is pinned to a particular commit; it does not track a branch head. When you update a submodule, Git checks out that particular commit only. That means .git/HEAD contains the commit hash, not a branch ref.

There may be one or more branch heads pointing to this commit, but that's kind of irrelevant. Only when HEAD contains a branch ref, not a commit hash, will git branch show you are on a branch.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜