Sometimes when working with git submodules, submodules may be accidentally updated and committed. If you end up in such a situation where a submodule was accidentally bumped forward on you, and you’re in a bad state, here’s how you can roll things back.
Checkout a previous commit where things worked
git checkout COMMIT-HASH-HERE
You can find the hash for your target commit by looking through your commit log.
Take a look at what commit hashes your submodules are set to
git submodule status
Either copy these hashes, or open another terminal for the remainder of the steps.
Switch back to the head of your branch
git checkout BRANCH-NAME
Go into each submodule directory, and checkout the associated commit hashes you’ve identified in step 2.
cd submodule-dir && git checkout WORKING-COMMIT-HASH
Verify everything works. Build and/or test your project.
Add and commit the changes you made to your submodule hashes.
Submodules can be tricky to use if you’re not used to them. The above steps got me out of quite a pickle today, and I hope it saves you some time.