VS2022 - Git Changes with submodule always shows change
Asked Answered
C

2

5

I have a large solution (CoreServices) that utilizes a common library (Common). I have another large solution that also utilizes the common library so submodules seemed like the right answer. Most of the time, they are.

VS2022 is supposed to have support for these submodules. However, in my Git Changes window, it ALWAYS says I have a modified submodule reference - and it doesn't matter what branch I'm on. I can't stage the change...or undo it. Trying to commit tells me there are no files. I've thought maybe I'll just find wherever the commit hash is living on the superproject and update it but to no avail.

Can anyone explain this behavior?

Changes on Common - can't go forward or back - not even switching branche

Cloudcapped answered 11/5, 2022 at 14:36 Comment(3)
No idea - I have the same behaviour and its annoying.Morpheus
I was able to get around it by navigating to the main folder and issuing a 'git add Common' command in the Package Manager window. Then commit with a comment. That gets me where I need to be. But I still don't understand the underlying issue. I find Git one of those things that is really easy to use until something goes wrong and then you need a PhD in it to not hurt yourself. :|Cloudcapped
I honestly thought it was a VS thing. But jumping out to the terminal showed me it was actually a git thing. I forced a reset of my submodules like so: ``` git submodule foreach --recursive git reset --hard ``` And that fixed it for me (and it works in all my repos pointing to the same submodule).Morpheus
M
6

For anyone looking at this.

There seems to be some different cases where this might happen. For me the submodule was stuck in a modified state and doing git restore modulename or git checkout modulename or any variations on git submodule update did nothing.

Resetting the submodule worked for me: git submodule foreach --recursive git reset --hard

Alternatively if that breaks you can try:

git submodule deinit -f .
# Initialize again
git submodule update --init --recursive
Morpheus answered 23/5, 2022 at 8:56 Comment(2)
When I did this, the modified status disappeared, but the changes I had pushed to the remote repo were reverted locally.Encarnacion
I've had this issue on one of my repositories for 4 years now. This is the first answer I've found that has actually worked.Dira
M
0

I right clicked on that PTO thing, and clicked on a button called: Submodule Update

And the PTO thing disappeared.

Morula answered 29/5, 2023 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.