Git子模块:指定一个分支/标签 [英] Git submodules: Specify a branch/tag

查看:1617
本文介绍了Git子模块:指定一个分支/标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git子模块如何加上-b 工作?



在添加一个具有特定分支的子模块后,新的克隆回购(在 git submodule update --init 之后)将在特定的提交中,而不是分支本身( git status 在子模块上显示当前不在任何分支上)。

我无法在 .gitmodules .git / config 关于子模块的分支或任何特定的提交,那么git是如何计算出来的?



另外,是否可以指定标记而不是分支?



PS:我正在使用 1.6.5.2




习惯这样做有点困惑,但子模块不在分支上。就像你说的那样,它们只是一个指向子模块存储库特定提交的指针。

这意味着,当其他人检出你的存储库或者提取你的代码时,并执行git submodule更新,子模块将签出到特定的提交。

对于不经常更改的子模块来说,这非常棒,因为项目中的每个人都可以在相同的提交下拥有子模块。



如果您想将子模块移动到特定标签:

  cd submodule_directory 
git checkout v1.0
cd ..
git add submodule_directory
git commit -m将子模块移至v1.0
git push

然后,另一个希望将submodule_directory更改为该标记的开发人员,请执行此操作

  git pull 
git子模块更新

git pull 其子模块目录指向的更改。 git submodule update 实际上会合并到新代码中。


How does git submodule add -b work?

After adding a submodule with a specific branch, a new cloned repo (after git submodule update --init) will be at a specific commit, not the branch itself (git status on the submodule shows "Not currently on any branch").

I can't find any information on .gitmodules or .git/config about the submodule's branch or any specific commit, so how does git figure it out?

Also, is it possible to specify a tag instead of a branch?

PS: I'm using 1.6.5.2.

解决方案

Note: Git 1.8.2 added the possibility to track branches. See some of the answers below.


It's a little confusing to get used to this, but submodules are not on a branch. They are, like you say, just a pointer to a particular commit of the submodule's repository.

This means, when someone else checks out your repository, or pulls your code, and does git submodule update, the submodule is checked out to that particular commit.

This is great for a submodule that does not change often, because then everyone on the project can have the submodule at the same commit.

If you want to move the submodule to a particular tag:

cd submodule_directory
git checkout v1.0
cd ..
git add submodule_directory
git commit -m "moved submodule to v1.0"
git push

Then, another developer who wants to have submodule_directory changed to that tag, does this

git pull
git submodule update

git pull changes which commit their submodule directory points to. git submodule update actually merges in the new code.

这篇关于Git子模块:指定一个分支/标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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