Why does git not see the changes in my submodules anymore?
Asked Answered
B

4

8

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 :/

Bevash answered 11/4, 2022 at 7:8 Comment(2)
What do you get for git submodule status ?Halpern
I suspect you've run something that in effect did git submodule update, which put you back on the old submodule commit. You should git add the submodule in the superproject and run git commit to record, in a new superproject commit, the new hash ID for the submodule.Bobbybobbye
B
5

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!

Bevash answered 13/4, 2022 at 19:57 Comment(0)
C
2

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)

Closing answered 11/4, 2022 at 7:31 Comment(6)
next time it happens I will check if this helps :) question though: how could any of this be changed from simple "git add, git commit, git push" usage, I never do anything fancier than that to trigger the problemBevash
@Bevash Those are git config settings only. If you have upgraded Git recently, some of their default value might have change.Closing
ok, it's happening again, when I do git config -l, i see nothing related to the two options you mentioned...Bevash
@Bevash Is there any .gitattributes files which could declare content filter drivers changing the content automatically on checkout?Closing
i don't have a .gitattributes fileBevash
Thanks, I had .git folder that was turning me crazy... not even chatGPT could help :)Bats
A
0

Restarting my computer solved the problem. VSCode was the issue as well probably.

Arvind answered 6/7, 2022 at 13:47 Comment(0)
T
0

The problem for me was apparently a git bug (possibly only on Windows?).

git version 2.33.1.windows.1 exhibited the problem.

I don't have Visual Studio installed, rebooting didn't fix it, but after updating to git version 2.38.1.windows.1 the problem was solved.

Tortilla answered 2/12, 2022 at 1:20 Comment(1)
Interesting! Will try to update to latest git as wellBevash

© 2022 - 2024 — McMap. All rights reserved.