开发者

Tagging an old commit of a submodule with git

I have a git project (repo1) including a single submodule (repo2). What I would like to achieve is to tag my project using an older commit of my submodule (like HEAD - 3).

I tried with a checkout of the submodule to the commit I want, but checkout is wrong since, committing in my project won't track the proper revision. I tried resetting my submodule to the commit I want, commit the project, and then pulling the submodule and committing the project, which is also wrong because:

$ git submodu开发者_开发知识库le update 
fatal: reference is not a tree: 2c3d1a5936aa9469ecc1442cd4b101e1bbd3aada
Unable to checkout '2c3d1a5936aa9469ecc1442cd4b101e1bbd3aada' in submodule path 'repo2'

What would be the best -- as well as nicest -- procedure ?


Git submodule head 'reference is not a tree' error gives a beginning of an answer, but it stills links the HEAD of repo2 and not a chosen commit...

Suppose now that the tag is done, how can I tell my repo1 to set repo2 in the proper state for a tag:

 git checkout 0.0.1

According to git submodule update, a simple

 git submodule update

should suffice. It doesn't checkout my submodule to the specified commit. Why ? Is that a ... bug ?


This question seems really hard, but it is not -- way from that.

The full procedure, starting from a git repo (repo1) with a submodule (repo2).

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

Now, if I need to tag an old commit of my repo2, here's what I'd do:

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

adding is important to update the gitlink to repo2's commit hash

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

Now, why did the submodule update didn't work ? The fact is I kept on trying to checkout a commit associated to a tag of repo1

$ git checkout TAGNUMBER
$ git submodule update

This didn't work only because (note to self) I forgot that:

One shall tag AFTER committing

So there was no real trick here, simply a little pitfall that may happen again for some of us, hopefully they'll end up here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜