使用git标记子模块的旧提交

时间:2011-05-13 12:34:00

标签: git git-submodules git-tag

我有一个git项目(repo1),包括一个子模块(repo2)。 我想要实现的是使用我的子模块的旧提交(如HEAD - 3)标记我的项目。

我尝试将子模块签出到我想要的提交,但是checkout 错误,因为在我的项目中提交将不会跟踪正确的修订。 我尝试将我的子模块重置为我想要的提交,提交项目,然后拉动子模块并提交项目,这也是错误的,因为:

$ git submodule update 
fatal: reference is not a tree: 2c3d1a5936aa9469ecc1442cd4b101e1bbd3aada
Unable to checkout '2c3d1a5936aa9469ecc1442cd4b101e1bbd3aada' in submodule path 'repo2'

什么是最好的 - 以及最好的 - 程序?


Git submodule head 'reference is not a tree' error给出了一个答案的开头,但它仍然链接了repo2的HEAD而不是选择的提交...

现在假设标签已完成,如何告诉我的repo1将repo2设置为适当的标签状态:

 git checkout 0.0.1

根据git submodule update,简单

 git submodule update

应该足够了。它不会将我的子模块签出到指定的提交。为什么?那是...... bug

1 个答案:

答案 0 :(得分:2)

这个问题似乎很难,但事实并非如此。

完整的程序,从带有子模块(repo2)的git repo(repo1)开始。

$ git clone git@git:myproject.git
$ cd myproject
$ git submodule update --init

现在,如果我需要标记我的repo2的旧提交,这就是我要做的事情:

$ cd repo2
$ git checkout SOMECOMMITHASHORTAGORELSE
$ cd ..
$ git add repo2

addgitlink更新为repo2的提交哈希非常重要

$ git commit repo2
$ git tag TAGNUMBER
$ git push (--tags if you want to push the tag also)

现在,为什么submodule update不起作用?事实是我一直试图检查与repo1标签相关的提交

$ git checkout TAGNUMBER
$ git submodule update

这不起作用只是因为(注意自己)我忘记了:

  

一个人应该在提交后标记

所以这里没有真正的伎俩,只是我们中的某些人可能会再次发生一些小陷阱,希望他们最终能在这里结束。