添加Git子模块时如何指定分支/标签? [英] How can I specify a branch/tag when adding a Git submodule?

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

问题描述

git submodule add -b如何工作?

在添加具有特定分支的子模块之后,新的克隆存储库(在git submodule update --init之后)将处于特定提交状态,而不是分支本身(子模块上的git status显示当前不在任何分支上").

After adding a submodule with a specific branch, a new cloned repository (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").

我在.gitmodules.git/config上找不到有关子模块的分支或任何特定提交的任何信息,那么Git如何解决呢?

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?

我正在使用1.6.5.2版.

I'm using version 1.6.5.2.

推荐答案

注意:Git 1.8.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.

这意味着,当其他人签出您的存储库或提取您的代码并进行git子模块更新时,该子模块将签出到该特定提交.

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

然后,另一个想要将submodule_directory更改为该标签的开发人员,执行此操作

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

git pull
git submodule update --init

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天全站免登陆