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")
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 .
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 .
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
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.
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.
In my case it was just my stupidity - I was in the wrong folder:
(*)Error was:
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With