Reputation: 5477
This is similar to Submodule commited branch no longer available but different such that its solution isn't applicable.
I just cloned a repo, and it has submodules, I have done a submodule update/init as well.
git clone ... foo && cd foo && git submodule update --init
I am on master
, I want to checkout a branch bar
. When I try, it fails; I have determined from the error and checking the repo's that git is unable to check out the submodule properly because the commit that the submodule used to point at is no longer in that repository. Submodule's head/current commit of the submodule file is present in that submodule.
For completeness the error is :
fatal: failed to unpack tree object
error: Submodule 'x' could not be updated.
error: Cannot update submodule:
xAborting
I get the idea here, git can't do it because the submodule's commit hash can't be found and git doesn't want to put the working repository in a 'messed up state', however this seems to leave me with no way to fix it locally.
What can I do so I can update that submodule in the current repo to point at a valid commit?
Let's assume for the moment that
git
Upvotes: 1
Views: 266
Reputation: 314
You could checkout without the submodules
git checkout --no-recurse-submodules <BRANCH>
Upvotes: 0
Reputation: 5477
Until someone gives a good answer the hack I used to get around this, which is absolutely deplorable, is to deinit the remote checkout the branch, delete the folder and then re-add it ( which re-clones) it. This is abysmal and there simply must be a better way than this. As such I am not accepting my own answer right away.
git submodule deinit x
git checkout <BRANCH>
git rm x
git submodule add <URL for x> x
git add .gitmodules
git add x
git commit -m'resetting submodule x'
and then eventually push it.
Upvotes: 1