modified content in git submodule, but git submodule says up to date
Asked Answered
F

4

8

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")
Furnish answered 14/1, 2015 at 12:30 Comment(0)
U
5

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
Unexampled answered 14/1, 2015 at 12:47 Comment(4)
if i run git add example/submod and then git status, i get the same message that the changes are not staged for commit :(Furnish
What shows "git remote -v"? Maybe you entered a wrong remote? Also check "git diff HEAD..origin/master" in your submodule. I guess the problem is that your dev branch isn't aligned with your origin/master.Unexampled
the remotes are correct for both main and submoduleFurnish
oops, just edited answer. please check "git diff HEAD..origin/master" in your submoduleUnexampled
W
3

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.

Wry answered 27/5, 2016 at 14:48 Comment(0)
W
1

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.

Walrus answered 14/1, 2015 at 16:32 Comment(0)
T
1

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/
Trigg answered 18/7, 2019 at 8:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.