10

I would like to tag all of the submodules of my project. I tried to do that with:

git submodule foreach git tag tagName

... but it appears to just return with no errors, having done nothing.

Edit: Here are the results of my attempt:

enter image description here

Can someone tell me how to properly tag all submodules?

Note: this a very similar question to this post, but the answer for that one suggested to rely on the submodule refs in the super-project. I, however, would actually like a tag in the submodule's repo.

Eric
  • 1,414
  • 3
  • 16
  • 35
  • 1
    That did it. What response did you expect to see? – jthill Jun 01 '17 at 23:28
  • I edited the original post so you can see that I don't get any tags out of the deal. – Eric Jun 02 '17 at 17:50
  • But now, I suggest reading the accepted answer below. @VonC was able to point me in the direction of why my command wasn't working. – Eric Jun 06 '17 at 00:06

1 Answers1

18

First, make sure your submodule folder have a content:

git submodule update --init --recursive

Then, simply do:

 git submodule foreach git tag -l

You should see, for each submdule, tagName.
Meaning your previous command did indeed tag those submodules.

I would recommend to make an annotated tag though, not a lightweight one:

git submodule foreach git tag -m "tagName" tagName

That means you can push that tag from each submodule.

If you just tag at the parent repo level, that will include the submodule gitlink, that is their SHA1. That could be enough in your case.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I edited the post above to show the list of resulting tags (none) ... even with an annotated tag. (And in my use case I do, in fact, want a tag on the repo for the submodule, rather than only the parent having the reference to the tagged submodule commit) – Eric Jun 02 '17 at 17:51
  • @Eric Did you do a `git submodule update --init --recursive` first? – VonC Jun 02 '17 at 19:48
  • Very interesting! So, no, I hadn't. I didn't think that was necessary because I had done the `git submodule add` from this repo. I figured that was enough to ensure that the submodules were updated. But I ran the update as you suggested, and after that, the `git submodule foreach tag...` command ran and worked just fine. – Eric Jun 06 '17 at 00:04