3

Say I have a git submodule already setup, and the upstream commit history has rewritten (for example a rebase squash was preformed).

Say the commit my submodule head is set to no longer exits. So I want to set the head hash submodule's repo's head. How do I do that?

kev
  • 7,712
  • 11
  • 30
  • 41
  • Just as a note, the commit your submodule's head was set to does still exist. If you want to prevent it being garbage-collected (after ninety days or so) you can add your own reference to it with a tag or `merge -s ours`ing it into a `preserved-history` branch or however you want to do it. – jthill Oct 14 '13 at 23:16

1 Answers1

2

You can simply go in the submodule, do a git fetch, and checkout the HEAD you need.

cd mysubmodule
git fetch
git checkout origin/abranch

Then you go back to the parent repo, add and commit that new submodule SHA1 entry.

Note that you also can convert a submodule in order to follow the latest commits of a branch.
In that case, a simple:

git submodule update --remote

would be enough.

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