1

I have a submodule that tracks a branch. It is currently sitting at the head of the branch. But git submodule status comes up with a rather ugly tagging.
That commit is really the current head of the branch in question, both in the submodule and on the remote.

 % git submodule status
    168b1e6c54101dfa7b1b865197ab7ac660c56fcf common (tha-6-7-g168b1e6)
 % cat .gitmodules
    [submodule "common"]
    path = common
    url = git@github.com:basis-technology-corp/perceptron-segmentation-models.git
    branch = etrog-985-restructure

Where does the ugly string 'tha-6-7-g....' come from? It's not a tag on the commit at the top of the branch.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
bmargulies
  • 97,814
  • 39
  • 186
  • 310
  • What's your question? – Johnny Z Sep 30 '13 at 19:12
  • From that "ugly string", I can tell that the commit that can be referenced by the abbreviated SHA `168b1e6` is 7 commits after the tag or branch named `tha-6`. Read the manual page for `git describe` for more information. And, for the record, submodules do not track branches - they reference a specific commit. – twalberg Sep 30 '13 at 20:38
  • Oh? According to the current git doc they do track branches. See the -b option to git submodule add. – bmargulies Sep 30 '13 at 20:43
  • `git submodule add -b foo ...` adds a pointer into your main project that points to the *current* head of the `foo` branch in your submodule, so that part is true. However, that pointer does not automatically *track* - the `foo` branch can move on, and your main project will not notice until you explicitly tell it to. The `-b branch` option is mainly there to tell it to use something other than `master`. – twalberg Sep 30 '13 at 20:52
  • I didn't mean to say anything else. – bmargulies Sep 30 '13 at 21:54

1 Answers1

1

You submodule tracks a branch, yes: it is registered in the .gitmodules file.

 git config -f .gitmodules submodule.<path>.branch

But the submodule true nature doesn't change: its role is still to reference in your parent repo a fixed commit SHA1. That is what git submodule status displays, and that guarantee that anyone else cloning your repo will end up with the same submodule as the one you are currently seeing.

git submodule status

Show the status of the submodules. This will print the SHA-1 of the currently checked out commit for each submodule, along with the submodule path and the output of git describe for the SHA-1.

It is only when you do a git submodule update --remote that its SHA1 would change, in order to reflect the latest of a remote branch.
You would then need to commit the parent repo in order to register the new SHA1 of your submodule.

A parent repo always references a submodule SHA1, not a submodule branch.
Branch names can come and go, be renamed or deleted. That shouldn't influence the capacity of a parent repo to restore the exact content of a submodule.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I think I knew all that. What perplexed me, really, was the curious choice of a name for that commit. There's a tag that points to that commit, not to mention the branch label. So I guess I need to read the git describe description a lot more carefully. – bmargulies Oct 01 '13 at 10:42
  • @bmargulies yes, the name is entirely generated by `git describe`, following the same algorithm every time: suffixing the most recent tag that is reachable from a commit, following with the number of additional commits on top of the tagged object and the abbreviated object name of the most recent commit. – VonC Oct 01 '13 at 11:06