I've been work on this project locally from the late December of 2018.
Now decided to push it to the remote on Github.
When I ran git push -u <REMOTE_NAME> master
I got the message:
fatal: bad tree object c6117da288c2323cdb4d695dcd7cdfa6f1c0118d
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly
fatal: the remote end hung up unexpectedly
error: failed to push some refs to <REMOTE_URL>
Then after a bit research I ran git fsck
Checking object directories: 100% (256/256), done.
broken link from tree 2e4901579b09704ecb89e685630136bf3f217bd3
to tree c6117da288c2323cdb4d695dcd7cdfa6f1c0118d
..... A lot of dangling blobs and commits .....
missing tree c6117da288c2323cdb4d695dcd7cdfa6f1c0118d
I've navigated to the .git/с6
and didn't find a file with the name 117da288c2323cdb4d695dcd7cdfa6f1c0118d
Also had a backup of the project like a one month old. No such file there.
I had no idea you should manually backup git folder.
Then I ran git cat-file -p 2e4901579b09704ecb89e685630136bf3f217bd3
. The tree with the broken link to the missing tree. Got this.
040000 tree c6117da288c2323cdb4d695dcd7cdfa6f1c0118d players
Then somehow in the Github Desktop I've found two commits related with the missing tree. It turns out that this is a very old commits, from Dec 28 2018.
Fetched the SHA1 of these commits - 063babbd79d62bfc579b888b944047be6c79cb6d
and bc64df9f9f734dd3450c2bef240381538cc23d6c
Then ran git cat-file -p 063babbd79d62bfc579b888b944047be6c79cb6d
tree 06d7866339756b512bd6129667a33f8c38d464c0
parent 4be4f9a68440aeedd15e56f0a0ff03ed33100753
author <NAME> 1546007706 +0300
committer <NAME> 1546007706 +0300
<FULL COMMIT MESSAGE>
Then the same command for other commit. Got the same structure. With different tree and parent
tree 07a5f4aeff3b6dc1707720c0701727864152b817
parent 063babbd79d62bfc579b888b944047be6c79cb6d
Never got this problem when committing locally. Comes up only when I was trying to push to the remote. Problem with missing tree could be related with the fact that I've stored the project in Yandex.Disk folder. To synchronize between two PC's. Just moved the project out of that folder.
It looks like the only option to not lose all commits history from Dec 28 is a manual recreation of the missing tree. Like described here. Is it so? Now I doesn't really sure what to put in the missing tree contents. How to figure out which blobs should be there?
Some other related answers that I found useful during the research:
How can I repair a git repository with a missing object?
How to fix git error broken link from tree to tree?
How to fix a bad git tree object
Git recovery: "object file is empty". How to recreate trees?