可以更新git submodule来获取子模块中的标签吗? [英] Can git submodule update be made to fetch tags in submodules?

查看:636
本文介绍了可以更新git submodule来获取子模块中的标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个git仓库,它使用一个子模块,我想指向一个带注释的标签,但是当我做 git submodule update 新标签时,牵强。我可以通过cd进入子模块并在那里做一个 git fetch --tags 来获得子模块中的新标签,但是我真的想要完成所有这些工作外部,因为它是脚本。



我找不到任何在git文档中提出了一种获取 git submodule update 包含标签(我的git版本是1.7.3.5)。

显然还有另一种可能性 - 将子模块指向标签指向的提交而不是标签本身,但这似乎并不整齐。



是否有获得 git子模块更新包含标签?

解决方案>

git submodule ,所以很容易看出它在做什么 - 如果你使用的是打包版本,它可能在 / usr / lib / git-core / git-submodule 。本质上,它只是在子模块中运行 git-fetch ,如果它存储在主项目树中的对象名称(SHA1sum)与子模块中检出的版本不匹配, Koraktor指出



man git-fetch > 而kernel.org处于关闭状态)说它应该获取指向下载对象的所有标记,下载的对象将包含每个提交的每个提交的祖先。这意味着我很惊讶你没有在 git子模块更新上获取所有相关标签。



如果你真的想要的是你的脚本是试图设置一个新的子模块版本并提交结果,我不认为 git子模块更新是你想要的工具 - 这只是为了确保你的子模块是在正确的版本基础上的主要项目的提交。相反,你应该这样做:

 (cd my-submodule&& \ 
git fetch& amp; amp; amp; ;& \
git fetch --tags&& \
git checkout my-tag)
git add my-submodule
git commit -m'更新子模块添加一个额外的 git fetch --tags
以防万一您的标签不是指向下载提交的标签。)


显然还有另一种可能性 - 指向子模块在标签指向的地方,而不是标签本身,但这看起来并不简单。


嗯,唯一的存储在子模块的主项目树中的东西只是提交对象的散列,所以即使有一条命令说set my submodu对于该子模块中的 my-tag 标签,它最终只会存储与该标签相对应的哈希值......


I have a git repository which uses a submodule which I'd like to point at an annotated tag, but when I do git submodule update new tags don't get fetched. I can get new tags in the submodule by cd-ing into the submodule and doing a git fetch --tags there, but I'd really like to do all of this from the outside as it's scripted.

I can't find anything in the git documentation suggesting a way to get git submodule update to include tags (my git version is 1.7.3.5).

Obviously there is another possibility - to point the submodule at the commit which the tag points to rather than the tag itself, but this doesn't seem as neat.

Is there a way of getting git submodule update to include tags?

解决方案

git submodule is implemented as a shell script, so it's easy to see what it's doing — it might be at /usr/lib/git-core/git-submodule if you're using a packaged version. Essentially it just runs git-fetch in the submodule if it the object name (SHA1sum) stored in the main project's tree doesn't match the version checked out in the submodule, as Koraktor points out.

The documentation for git fetch (or man git-fetch while kernel.org is down) says that it should fetch every tag that points to a downloaded object, and the downloaded objects will include every commit that's an ancestor of every branch that's fetched. That means it's surprising to me that you don't get all the relevant tags on a git submodule update.

If it's the case that what you really want is for your script is to try to set a new submodule version and commit that result, I don't think that git submodule update is the tool that you want - that's just for making sure that your submodules are at the right version based on what's currently in the main project's commit. Instead you should just do something like:

( cd my-submodule && \
      git fetch && \
      git fetch --tags && \
      git checkout my-tag )
git add my-submodule
git commit -m 'Update the submodule to the "my-tag" version' my-submodule

(I added an extra git fetch --tags just in case your tag isn't one that points to a downloaded commit.)

Obviously there is another possibility - to point the submodule at the commit which the tag points to rather than the tag itself, but this doesn't seem as neat.

Well, the only thing that's stored in the main project's tree for the submodule is just the hash of the commit object, so even if there were a command that said "set my submodule to the tag my-tag in that submodule", it would end up just storing the hash corresponding to that tag anyway...

这篇关于可以更新git submodule来获取子模块中的标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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