3

here is the situation i faced. I have a repo containing a submodule. In the repo, i created a new branch to do some editing.

Then i found out i need an updated submodule, so i pulled down the submodule and kept working. I made a commit afterward, and merge the branch back to the master branch.

In the master branch, when i use "git submodule update", the submodule points back to an old version, but not to the updated one in the branch :(

I am wondering if git merges submodules reference? Can anyone help me?

LennonLam
  • 215
  • 1
  • 2
  • 10

1 Answers1

1

In your branch, after pulling the submodule 'xxx', you need to go back in the parent repo (in the folder which contains your submodule) and do a:

git add xxx
git commit -m "Updated submodule"

That will record an updated special entry of the index memorizing the new SHA1 for submodule 'xxx'.

That is that special entry which needs to be updated when you merge your branch back to master.

If you forget the git add/git commit step in the branch, the merge back to master would keep the special entry unchanged, still referring to the old SHA1.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I added the bounty because I have the same problem as OP - however I *have* added and committed the submodule in the original branch. It doesn't show up in the branch I merged into. – Steve Fallows Aug 23 '13 at 14:24
  • @SteveFallows "it doesn't show up" meaning "the submodule doesn't show up"? Or the submodule is there, but its updated content with the pulled SHA1 doesn't show up? – VonC Aug 23 '13 at 15:34
  • The latter - It is still the SHA1 of the original version, not the updated version that I committed in the other branch, before merging. There are other submodules in the project where this has been done OK - not sure what I fouled up here. – Steve Fallows Aug 23 '13 at 15:44
  • @SteveFallows Maybe this module was modified in both branches? As opposed to the other correctly updated submodules, which were modified only in the `dev` branch, before being merged back to `master`? – VonC Aug 23 '13 at 15:55
  • @SteveFallows Or that particular submodule has somehow lost its submodule status (check the `.gitmodules` file, and the `.git/modules` folder). A `git submodule update --init` might be in order. – VonC Aug 23 '13 at 15:56
  • Thanks, but it's neither of those. I've run git submodule update -- init many times while working on this. I've punted for now and directly updated the second branch. I'll see what happens on next merge. – Steve Fallows Aug 23 '13 at 17:26
  • 4 years later I can confirm I'm having the same problem. On my work branch, I updated a submodule from version A to version B. `git status` showed `modified: [submodule name] (new commits)`. I used `git add [submodule name]` and `git commit` to commit this update to the work branch. Then I checked out master, and merged the work branch into master. I expected the master would now reference version B of the submodule, but `git submodule update` changed it back to version A. I had to add and commit the submodule update on the master branch, separately to the work branch. – Chungzuwalla Nov 09 '17 at 00:42