tribbloid
tribbloid

Reputation: 3858

`git submodule sync`: why doesn't it do anything?

Considering this commit:

https://github.com/tribbloid/spookystuff/commit/08650c3565a823fb1a696afd7f1461681293a1fe

If I run the following command:

peng@pop-os:~/git/spookystuff$ cat .gitmodules 
[submodule "parent/showcase"]
    path = parent/showcase
    url = https://github.com/tribbloid/spookystuff-showcasepeng@pop-os:~/git/spookystuff$ git submodule sync
peng@pop-os:~/git/spookystuff$ git submodule update --init --remote --recursive
peng@pop-os:~/git/spookystuff$ git submodule status
peng@pop-os:~/git/spookystuff$ git submodule foreach git pull --rebase
peng@pop-os:~/git/spookystuff$ git submodule status

It can be seen that the number of submodule is still 0, contrary to the .gitmodule file

How did this happen? And what can be done to fix it?

Upvotes: 1

Views: 394

Answers (1)

philb
philb

Reputation: 3030

 Considering this commit:

https://github.com/tribbloid/spookystuff/commit/08650c3565a823fb1a696afd7f1461681293a1fe

In this commit, .gitmodules is changed to indicate that the submodule spookystuff-showcase should be cloned at path parent/showcase instead of spookystuff-showcase. But, the actual submodule object is removed: https://github.com/tribbloid/spookystuff/commit/08650c3565a823fb1a696afd7f1461681293a1fe#diff-8f1d364786f7b7fb36c0cd2e5b73810d4d1b435acfc890dad6da02ac7bf95101.

This is why all git submodule subcommands do nothing: there is no submodule object at that commit in your repository.

If the intention was to move the submodule, then ideally git mv spookystuff-showcase parent/showcase would have been used.

To fix it, you should restore the changes to spookystuff-showcase and then properly move it:

git clone https://github.com/tribbloid/spookystuff
git fetch origin 08650c3565a823fb1a696afd7f1461681293a1fe
git checkout 08650c3565a823fb1a696afd7f1461681293a1fe
git checkout HEAD~1 spookystuff-showcase
git mv spookystuff-showcase parent/showcase
git commit -m "re-add spookystuff-showcase at path parent/showcase" # or git commit --amend --no-edit
git submodule update --init # works

Upvotes: 1

Related Questions