Artyom
Artyom

Reputation: 3571

Can not push to Github: gitmodulesParse: could not parse gitmodules blob

After merging several git repositories into on using method from How do you merge two Git repositories?. I'm pushing it into Github but it fails with:

git push -u origin master
Counting objects: 755, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (518/518), done.
Writing objects: 100% (755/755), 29.91 MiB | 1.55 MiB/s, done.
Total 755 (delta 195), reused 481 (delta 128)
remote: error: bad config line 1 in blob .gitmodules
remote: error: object b13fc97cca572d71bf5dad31706d4691bb11a1e7: gitmodulesParse: could not parse gitmodules blob
remote: fatal: fsck error in packed object
error: unpack failed: index-pack abnormal exit
To github.com:...........git
 ! [remote rejected] master -> master (failed)
error: failed to push some refs to '[email protected]:...........git'

There was some submodules in some repository which I removed manually (rm pathtomodule\.git then rm .gitmodules). How to fix it or there are no other way, only remerge? git fsck --full --strict gives nothing.

Upvotes: 4

Views: 1457

Answers (1)

Ed'ka
Ed'ka

Reputation: 7148

I had the same situation (also merged repos and the same error). In my case some old commits indeed contained ill-formed .gitmodules. Since we don't use submodules in our merged repo and I didn't care to keep even valid .gitmodules the way I resolved the problem was to simply remove all .gitmodules files from the entire history. Note: this approach effectively rewrites the entire history keeping all commits as is (minus .gitmodules) but giving them new hashes.

There is a utility to do that.

Or, if you want to do it manually (pretty much copied from the utility):

git filter-branch --index-filter 'git rm --cached --ignore-unmatch .gitmodules' --force -- --branches --tags
rm -rf .git/refs/original/ .git/refs/remotes/ .git/*_HEAD .git/logs/
(git for-each-ref --format="%(refname)" refs/original/ || echo :) | xargs --no-run-if-empty -n1 git update-ref -d
git reflog expire --expire-unreachable=now --all
git repack -q -A -d
git gc --aggressive --prune=now

Upvotes: 2

Related Questions