如何使分离的HEAD的子模块连接到实际的HEAD上? [英] How to make submodule with detached HEAD to be attached to actual HEAD?

查看:320
本文介绍了如何使分离的HEAD的子模块连接到实际的HEAD上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将Git子模块添加到像这样的Git存储库时,

  git submodule add ssh:// server / proj1 / proj1 
git submodule init
git submodule update

添加的子模块将会在分离的HEAD 模式下。我不知道那是什么,但我知道该子模块将链接到目标存储库的特定版本。



我不知道它是如何实际工作,无论如何,它看起来像一个代理分支存在那里。我通过切换到master分支解决了这个问题。

  cd proj1 
git checkout master

这将切换当前分支的实际主控HEAD,但这不会更新联动。因此,如果您再次克隆整个存储库,它仍然会链接到旧版本。



如果我想让它与最新版本(HEAD)关联,我该怎么办?

更新2013年3月

<一个href =https://github.com/git/git/blob/master/Documentation/RelNotes/1.8.2.txt =nofollow noreferrer> Git 1.8.2 增加了追踪的可能性分支机构。


git子模块开始学习新模式




)(与集成超级项目gitlink中记录的提交相反) > #添加子模块来跟踪master分支
git子模块add -b master [URL to Git repo];

#更新您的子模块
git子模块更新--remote

另请参阅 Vogella关于子模块的教程






原始答案(2011年12月)


新增子模块处于分离的HEAD模式中

是的,子模块是关于引用特定的提交,而不是分支。

So:


  • 如果您签出提交SHA1(或标签),则表示处于分离的HEAD模式。

  • 如果您签出一个分支(就像您使用子模块的 master 分支一样),您可以在其上创建其他提交分支(但是您必须返回父代码库才能提交该父代,因为您需要记录您创建的新子模块提交)



有关更多信息,请参阅子模块的真实性质。 / p>

如果您一直想要另一个repo的最新提交,最简单的方法是将它们合并在一起(例如与子树合并)。

请参阅合并2个相同的仓库GIT 以获取详细信息和参考资料。


When I add a Git submodule to a Git repository like this,

git submodule add ssh://server/proj1/ proj1
git submodule init
git submodule update

the added submodule will be in detached HEAD mode. I don't know well what that is, but I know that the submodule will be linked to specific revision of the target repository.

I don't know how it actually works, anyway it looks like a proxy branch exists there. I solved this by switching to master branch.

cd proj1
git checkout master

This will switch current branch actual master HEAD, but this does not update the linkage. So If you clone the whole repository again, it will still be linked to old revision.

If I want to make it to be linked to most recent revision (HEAD) always, what should I do?

解决方案

Update March 2013

Git 1.8.2 added the possibility to track branches.

"git submodule" started learning a new mode to integrate with the tip of the remote branch (as opposed to integrating with the commit recorded in the superproject's gitlink).

# add submodule to track master branch
git submodule add -b master [URL to Git repo];

# update your submodule
git submodule update --remote 

See also the Vogella's tutorial on submodules.


Original answer (December 2011)

added submodule will be in detached HEAD mode

Yes, a submodule is about referencing a specific commit, and not a branch.
So:

  • If you checkout a commit SHA1 (or a tag), you are in a detached HEAD mode.
  • If you checkout a branch (like you did with master branch of the submodule), you can create other commits on top of that branch (but you will have to go back to the parent repo in order to commit said parent as well, for you need to record the new submodule commit you created)

See "True nature of submodules" for more.

If you always wanted the latest commit of another repo, the simplest way would be to merge them together (for instance with subtree merging).
See "Merge 2 same repository GIT" for the details and references.

这篇关于如何使分离的HEAD的子模块连接到实际的HEAD上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆