Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update git submodule who's history was rewritten

Tags:

git

rebase

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?

like image 275
kev Avatar asked Feb 03 '26 06:02

kev


1 Answers

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.

like image 143
VonC Avatar answered Feb 04 '26 19:02

VonC