12

The Project is having one sub module and is pointing to one particular SHA (ex 62726c) of that submodule.

So each time on running git submodule update --init the submodule directory is showing the changes of that SHA (62726c) only.

Recently I made change to the submodule and pushed the changes SHA (f81611) but as mentioned above the HEAD of the submodule is still pointing to old SHA 62726c .

CharlesB
  • 86,532
  • 28
  • 194
  • 218
Jyotsna Saroha
  • 678
  • 6
  • 13

2 Answers2

13

When doing git submodule update --init, you checkout the submodule to the revision registered by the project, which hasn't been updated, that's why you always see it reverted.

To change the revision of the submodule for the super project, check out the submodule to the SHA1 you want:

git checkout f81611

From the main project you'll see that the submodule is listed as being modified (git status). You need to commit this modification, as if the submodule was a normal file:

git add <path-to-submodule>
git commit -m "Update submodule XX so that it does YY"
CharlesB
  • 86,532
  • 28
  • 194
  • 218
3

The other option is to make your submodule follow a particular branch:
See "Git submodules: Specify a branch/tag"

Then a git submodule update --init --recursive --remote would be enough to check out the latest from that branch for all your repos which have specified a branch to follow.

If your pushed change SHA (f81611) was push on master of the repo, then git submodule update --init --remote would update the content of that submodule repo as used in the main parent repo.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Mixing `--remote` with `--recursive` may not be advisable if the submodule (and its sub-submodules) is maintained by a different team, because the submodule maintainers may not have tested their project with `--remote` themselves. An example is having the Boost super-project (https://github.com/boostorg/boost.git) as a submodule. – Tanz87 Dec 13 '18 at 18:23