Home > Software engineering >  Why does git not see the changes in my submodules anymore?
Why does git not see the changes in my submodules anymore?

Time:04-14

Windows user here. I have a C git project with a bunch of submodules. The directory structure looks something like this:

source
  apps
    myapp1
    myapp2
  externals
    submodule1
    submodule2
    ...
    submoduleN
  packages
    mypackage1
    mypackage2
CMakeLists.txt
Makefile
...

The submodules are my own work that I share between my projects (so I own and maintain them).

Cloning this is straightforward:

git clone ssh://blabla@blabla/blabla
git submodule update --init

Everything works for a while. When I change stuff in my submodules, and do git status, git recognizes this and says something like:

C:\blabla>git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)
        modified:   source/externals/XXX (modified content)

no changes added to commit (use "git add" and/or "git commit -a")

I go into the dirty submodule, add, commit and push the changes. Then, in the main project, git will notice I am now on a different commit:

C:\blabla>git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   source/externals/XXX (new commits)

no changes added to commit (use "git add" and/or "git commit -a")

This works fine, until suddenly it doesn't anymore. After working like this for a period of time (usually a day or two), git suddenly stops recognizing changes in one or more submodules. When I go into an affected submodule's directory and hit git status there, git sees the changes. But when I do the same in the main project, git no longer says that there is modified content in that submodule. And when I add, commit and push the changes in my submodule, git no longer recognizes that the submodule now is on a different commit. Trying git submodule update doesn't fix anything. It brings the affected submodule back to the commit it was on before things went wrong. But when I do git checkout master and then git pull to get my changes back, doing git status in the main directory still shows no changes for that submodule.

I know of only two ways to fix this:

  • deleting the whole project and re-cloning
  • cloning the submodule in a different unrelated directory, changing, committing and then pushing something (anything really), and then doing git pull in my project... weirdly enough THAT is what brings git around and everything works again.

Anyone got any idea what could cause this? Sorry for the super long post, tried to give as much context as possible.

EDIT: I have the problem again. git submodule sync fixes nothing. git submodule status shows the following:

 e773ebc7904dd5f695bfa56880bd0874207d57be source/externals/... (heads/master)
 9b3ef1bd87dd4a2ab0c527499162df84babff1de source/externals/... (remotes/origin/HEAD)
 99f672b772fa876a790b86d6900191fd3eba1d3e source/externals/THIS_ONE_GOES_WRONG (99f672b)
 27ed4009784093fa8a095415ec4666135dece821 source/externals/... (remotes/origin/HEAD)
 dd207664b563c4fe271c995fda7b1b93ec40f437 source/externals/... (remotes/origin/HEAD)

The weird part here is that the mentioned commit for the submodule going wrong is NOT the commit the submodule is actually one! It's on a different commit (a newer one), as shown when I do git log in the affected submodule:

commit c374f672a8ac8fc5d8f312a7cf75785c96ca5763 (HEAD -> master, origin/master, origin/HEAD)
Author: ...
Date:   Tue Apr 12 19:29:14 2022  0200

    <commit message>

commit 99f672b772fa876a790b86d6900191fd3eba1d3e
Author: ...
Date:   Tue Apr 12 16:15:03 2022  0200

    <commit message>

But whatever I do, git submodule update and then pull in the affected submodule, git does NOT recongize ANYTHING in it anymore. Changed content, changed commit, it's somehow looking at stale data :/

CodePudding user response:

Check first your git config -l ouput, for any setting related to submodule.

For instance, set status.submoduleSummary to true, or or diff.ignoreSubmodules to false.

Check also for any .git subfolder which would transform a submodule folder into a nested Git repository (completely ignored by a git status in the parent repository)

CodePudding user response:

I think I have found the answer. I'm using Visual Studio 2022, and it seems it spawns an immense amount of git processes that somehow linger in the background. When these processes are still running, I experience the problems as described. But as soon as I kill these processes, or simply reboot, the entire problem goes away and git behaves again as expected.

It seems that it's not git's or my fault, but an issue with VS2022's source control system. I will disable git in VS2022 and see if the problem repeats!

  • Related