git submodule modified files status
Asked Answered
C

3

55

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.

Carlisle answered 15/5, 2011 at 4:30 Comment(1)
I encountered this when I had a git repo in a sub-directory that I did not know about, which caused me no end of confusion. It kept listing the directory as modified, even though I had added the files to the parent repository. Thanks for the question - cleared things up nicely!Smashup
M
91

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
Misti answered 15/5, 2011 at 6:42 Comment(6)
Thank you. git version 1.7.0.4Carlisle
git diff did indicate -dirty, and git status showed all the files as modified. Thanks for the answer, I was concerned about modifying a submodule and committing it. I added + committed the submodule, and still getting the -dirty. Looks like a line ending issue. I went into the path and 'git add .' and got a scroll of these warning: CRLF will be replaced by LF I had autocrlf input set.Carlisle
I found a repo with an updated version of git. git version 1.7.5.1 Installed that, and no longer have the issue so I'll be happy with that result for now.Carlisle
@Poe: Great, I'm glad to hear that you managed to sort that out.Misti
@MarkLongair great explanation, mine was the latter. Does this mean if I just want to update to head, I can call submodule update instead of having to CD into the folder and doing an update?Eterne
@Blundell: yes, approximately - git submodule update will actually checkout the submodule version that's specified in the index of the "supermodule", rather than HEAD, but in many cases that's the same.Misti
B
11

I used the following git command to resolve this problem:

git submodule update --init  --recursive
Bores answered 22/5, 2018 at 7:50 Comment(0)
G
7

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/*
Glassco answered 21/10, 2013 at 9:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.