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

1

1

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?

Casias answered 20/10, 2023 at 3:12 Comment(4)
Did you manually change the .gitmodules file, or use git submodule add to properly add a submodule?Rankin
good question: it was cherrypicked from another branch, but apparently git cherrypick malfunctioned and only apply changes in .gitmodule. I'm still looking for the right command to cherrypick .git/configCasias
I think the easiest solution is to just once run git submodule add https://github.com/tribbloid/spookystuff-showcase parent/showcase. That works even if your .gitmodules exists already, but sets the according .git/config correctly.Forest
@TorgeRosendahl thanks a lot, it is probably impractical for a lot of submodules tho (e.g. PX4-autopilot)Casias
V
1

 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
Vostok answered 24/10, 2023 at 13:56 Comment(5)
thanks a lot, so there is no command to resolve this conflict?Casias
I'm not sure what you mean by "conflict". There is no Git merge conflict happening in the above sequence...Vostok
sorry I mean "inconsistency" between the .gitmodule file and the hidden commit reference under .git directory (which, if considered part of the project dependency, shouldn't be hidden)Casias
Well, the commands I mention can be used to resolve the inconsistency. I'm not sure what else you would like to do ? maybe I'm missing something.Vostok
I'm afraid that's not a generalisable solution, first, it will be wildly verbose for projects with many submodules (e.g. PX4-autopilot), second, the problem arise from a cherrypicking, so the working tree will be lost if re-clone it from scratchCasias

© 2022 - 2024 — McMap. All rights reserved.