So here's what you need to know:
- Repo A was a large legacy repo used in several other projects as a submodule on GitHub Enterprise.
- While migrating Repo A to GitLab, we found that some commits deep in the history had their data corrupted and were causing the migration to fail.
- In order to remove these corrupted files, we had to rewrite the git history around the corrupted commit.
- Repo B uses Repo A as a submodule.
I have been attempting to update Repo B by doing the following:
- Clone Repo B from GitLab
- Update the path in .gitmodules to point to the new (GitLab) location of Repo A
git submodule init
- Confirm that Repo A's url is correct and pointing to the new (GitLab) Repo A
cd repo-b/repo-a
git checkout $hash
where$hash
is the exact same commit in Repo A that we used to point to, but with the new hash because history was rewritten.
I keep getting this error:
fatal: reference is not a tree: 01b517847508dd5942887950e4a5ab1468bb21b4
I can't figure out what I'm doing wrong, every answer I've seen seems to imply that I should be able to checkout a specific hash in the submodule and then commit that change to the repo.
Also, just for clarification, I did confirm that my hash is correct and exists by checking it out in the new (GitLab) Repo A, so it's there.
CodePudding user response:
I found a solution! I can't explain why it works, but it fix the error.
I had previously tried this with a git submodule update
between step 3 and step 5, and that didn't seem to work. However:
git submodule init
git submodule update --checkout
Did in fact allow the hash checkout to succeed in the submodule.