简体   繁体   中英

Update submodule after rewriting commit history

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:

  1. Clone Repo B from GitLab
  2. Update the path in .gitmodules to point to the new (GitLab) location of Repo A
  3. git submodule init
  4. Confirm that Repo A's url is correct and pointing to the new (GitLab) Repo A
  5. cd repo-b/repo-a
  6. 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM