Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

modified content in git submodule, but git submodule says up to date

I cant push the changes I made to a git submodule. I have pushed the main project, and get this

mainProject$ git status
On branch myBranch
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

     modified:   example/submod (modified content)

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

But when trying to push the changed in the submodule i get

submod$ git status
On branch dev
Your branch is up-to-date with 'origin/dev'.

The output of the git --version is

git version 1.9.3 (Apple Git-50)

When I run

mainProject$ git diff example/submod
Submodule example/submod contains modified content

What is happening here? I can't add the changes from the main project either

mainProject$ git add example/submod
mainProject$ git status
On branch myBranch
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

   modified:   example/submod (modified content)

no changes added to commit (use "git add" and/or "git commit -a")
like image 768
glasspill Avatar asked Jan 14 '15 12:01

glasspill


People also ask

How do you fix a dirty submodule?

You can fix it by: either committing or undoing the changes/evolutions within each of your submodules, before going back to the parent repo (where the diff shouldn't report "dirty" files anymore). To undo all changes to your submodule just cd into the root directory of your submodule and do git checkout .

Will git pull update submodules?

Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .


4 Answers

You have checked out a different commit in your submodule than it is commited in your main repository. You can either checkout the associated commit of the submodule by

git submodule update

...or you add this submodule, commit and push it with the current changes:

git add example/submod
git commit -m 'new commits in submodule'
git push origin myBranch
like image 138
clash Avatar answered Nov 12 '22 05:11

clash


I had this problem too and to fix it I had to remove the submodule and re-add it. Like this:

git submodule deinit PathTo/SubmoduleName
git rm PathTo/SubmoduleName
sudo rm -rf .git/modules/PathTo/SubmoduleName

git submodule add https://github.com/username/SubmoduleName.git

After this my project now shows correctly there are no changes to commit. I guess its just a bug in Git's submodule implementation.

like image 44
malhal Avatar answered Nov 12 '22 05:11

malhal


You've got content (a commit) recorded as the current state of the submodule in your project, and your submodule has that commit checked out (since status didn't mention any differences in commit ids), but something has modified that content since checkout or commit.

like image 40
jthill Avatar answered Nov 12 '22 04:11

jthill


In my case it was just my stupidity - I was in the wrong folder:

  • mainProject showed "submodule modified content"
  • submodule* showed "no changes"

(*)Error was:

  • The submodule folder where I executed git status was the actual clone of the submodules repository, let's call it ~/workspace/mySubModuleRepo and I just thought I was executing this comment in ~/workspace/mainProject/mySubModule/
like image 20
hb0 Avatar answered Nov 12 '22 05:11

hb0