从Bitbucket迁移GitHub遇Git nullSha1问题求解决方案
解决Git迁移时"nullSha1: contains entries pointing to null sha1 for submodule"报错的方案
1. 定位问题子模块
先在本地克隆问题仓库,执行以下命令排查所有子模块状态:
git submodule status --recursive
输出结果中带有null或-前缀的条目,就是指向空SHA1的问题子模块。
2. 修复子模块引用
场景1:子模块已废弃
直接移除无效子模块:
git submodule deinit -f -- path/to/submodule git rm -f path/to/submodule rm -rf .git/modules/path/to/submodule
提交修改:
git commit -m "Remove invalid submodule with null SHA1"
场景2:子模块需保留
先检查.gitmodules和.git/config中的子模块配置,确认远程地址有效性,再执行同步更新:
git submodule sync --recursive git submodule update --init --recursive --force
若仍无效,手动修改.gitmodules里的子模块url为有效远程仓库地址,重新执行上述同步命令。
3. 清理Git无效对象
如果问题仍存在,清理Git数据库中的冗余无效引用:
git gc --prune=now git fsck --full
确认git fsck无无效SHA1提示后,重新提交修改。
4. 重新执行迁移
修复完成后,推送本地仓库到GitHub目标地址:
git remote add github https://github.com/your-username/your-repo.git git push github --all git push github --tags
内容的提问来源于stack exchange,提问作者Nagendra S.P
相关产品推荐
相关产品推荐

