gpt4 book ai didi

git - 如何使带有分离 HEAD 的子模块附加到实际 HEAD?

转载 作者:IT王子 更新时间:2023-10-29 01:09:21 28 4
gpt4 key购买 nike

当我像这样将 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 月更新

Git 1.8.2添加了跟踪分支的可能性。

"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

另见 Vogella's tutorial on submodules .


原始答案(2011 年 12 月)

added submodule will be in detached HEAD mode

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

  • 如果您 check out 提交的 SHA1(或标签),则您处于分离的 HEAD 模式。
  • 如果您 checkout 一个分支(就像您对子模块的 master 分支所做的那样),您可以在该分支之上创建其他提交(但您必须返回到父仓库为了也提交所述父模块,因为您需要记录您创建的新子模块提交)

有关更多信息,请参阅“True nature of submodules”。

如果您一直想要另一个仓库的最新提交,最简单的方法是将它们 merge 在一起(例如使用子树 merge )。
有关详细信息和引用,请参阅“Merge 2 same repository GIT”。

关于git - 如何使带有分离 HEAD 的子模块附加到实际 HEAD?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8642668/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com