git submodule modified files status

GitGit Submodules

Git Problem Overview


I've added a submodule in my main git folder tree and haven't changed anything but it's showing up modified. What do I do about this?

$ git status
# On branch master
# Changed but not updated:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#    modified:   example.com/soundmanager
#
no changes added to commit (use "git add" and/or "git commit -a")

I've tried a git submodule update, but it doesn't do anything.

Git Solutions


Solution 1 - Git

The way that the status of git submodules is reported has changed a lot over recent versions of git, so you should really include the output of git --version as well for us to be able to help accurately.

However, in any case, the output of git diff example.com/soundmanager should tell you more. If you see output with the same commit name, but with -dirty added to the new version, e.g.:

diff --git a/example.com/soundmanager b/example.com/soundmanager
--- a/example.com/soundmanager
+++ b/example.com/soundmanager
@@ -1 +1 @@
-Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7
+Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7-dirty

... than that means that git status in the submodule isn't clean - try cd example.com/soundmanager and then git status to see what's going on.

On the other hand, if you see different commit versions, e.g.:

diff --git a/example.com/soundmanager b/example.com/soundmanager
index c4478af..c79d9c8 160000
--- a/example.com/soundmanager
+++ b/example.com/soundmanager
@@ -1 +1 @@
-Subproject commit c4478af032e604bed605e82d04a248d75fa513f7
+Subproject commit c79d9c83c2864665ca3fd0b11e20a53716d0cbb0

... that means that the version that your submodule is at (i.e. what you see from cd example.com/soundmanager && git show HEAD) is different from the version committed in the main project's tree (i.e. what you see from git rev-parse HEAD:example.com/soundmanager). If the former is right, you should add and commit the new version of the submodule in your main project, with something like:

git add example.com/soundmanager
git commit -m "Update the soundmanager submodule"

On the other hand, if the latter is what you want, you can change the version that the submodule is at with:

git submodule update example.com/soundmanager

Solution 2 - Git

I used the following git command to resolve this problem:

git submodule update --init  --recursive

Solution 3 - Git

I got in this state by mistakenly adding a submodule by specifically adding a directory instead of just adding the content of a new directory.

I needed just to remove the submodule like this:

git rm --cached path/to/my/new_directory

And then add the contents like I intended to in the first place:

git add path/to/my/new_directory/*

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionPoeView Question on Stackoverflow
Solution 1 - GitMark LongairView Answer on Stackoverflow
Solution 2 - Gitblacet wangView Answer on Stackoverflow
Solution 3 - GitaweView Answer on Stackoverflow