When you apply a submodule patch in Git, it leaves you with a working copy that has the "submodule pointer" dirtied but the actual submodule untouched:
$ git status On branch ... Changes to be committed: (use "git reset HEAD <file>..." to unstage) modified: philter 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) modified: philter (new commits)
So, if you're applying D123 and submodule/ was previously pointed at commit "A" but D123 updates it to point at commit "B", you get this after git apply ...:
- Git index says "submodule/ = B".
- On disk, "submodule/ = A".
Now, if you git add --all or git commit --all, git picks up the "change" on disk as an intended modification of the submodule. This puts the submodule back to "A" and overwrites/undoes the "pointer" update that's trying to make it point to "B".
To avoid this, update submodules after applying the patch.
Also, every time we modify the working copy, just update submodules.