1

From reading through the Git documentation (specifically this page, as well as associated command reference pages: https://git-scm.com/book/en/v2/Git-Tools-Submodules) I still felt it was a little unclear exactly when the associated SHA for the submodule, as reported by "git diff --cached SomeSubModule", gets updated, as the text is not very explicit on the subject.

What appears to be implied is that the reference updates when the currently checked out commit in the submodule is changed (such as via a "git submodule update --remote") and then a commit is made in the superproject to reflect this change. However, I would like to verify if that is correct or if I misunderstood.

  • I have not worked with submodules since the bad old days (Git 1.5, 1.6, maybe early 1.7) and am not sure what's happened since then. Back then you had to explicitly `git add path/to/submodule`—note the lack of a trailing slash here!—to get Git to update the SHA for the next commit. What's definitely unchanged is that for the new SHA to be in place, it must get updated in the index. What `git commit` commits is "whatever is in the index". – torek Nov 06 '17 at 23:01

1 Answers1

1

the reference updates when the currently checked out commit in the submodule is changed

Yes, but not just on git submodule update --remote.
It changes if any commit is made (or fetched) in the submodule.

and then a commit is made in the superproject to reflect this change

More precisely, to add and commit a changed element, that element being the gitlink (special entry in the main repo index)
You can also update that gitlink from the parent repo: see "Git Submodule has a wrong reference to its remote repository".

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250