Search code examples
gitgit-submodules

Git status from project root shows submodule changes, but in submodule, none are available


From the root of my project, the submodule seems to show changes to commit. However, when I change to that directory, no changes are waiting. How do I interpret this?

Noting that changes from the submodules were added, committed and pushed from the root of the submodule and not the root of the project. Perhaps there lies the confusion?

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   path/to/submodule (new commits)

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

$ cd path/to/submodule

$ git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

$ git submodule status
+bdaa5b15120853ab8c3b502733e7337e825c51a1 path/to/submodule(heads/master)

Solution

  • Git submodules work the following way. In a project that has submodules the superproject remembers the current commit for every submodule. If a submodule changes (have new commits) the superproject notes this. You should make the superproject remember these new commits:

    # from the top of the superproject
    git add path/to/submodule
    git commit -m "Update submodule"
    

    or simply

    git commit -m "Update submodule" path/to/submodule