How to fix git repository broken by interrupted git fetch?

nrz picture nrz · May 20, 2012 · Viewed 16.3k times · Source

If git fetch gets interrupted for example by Ctrl-C or caused by connectivity problems, after that git fetch and also git pull fail to work.

user@computer:~/code/openttd-git$ git fetch
^C
user@computer:~/code/openttd-git$ git fetch
error: Unable to find 22d90742fc79a9011fb86ee03d8aeea66bc12657 under http://git.openttd.org/openttd/trunk.git
Cannot obtain needed object 22d90742fc79a9011fb86ee03d8aeea66bc12657
error: Fetch failed.

I believe this is not related to the repository. Using git clone to create a copy of this broken local repository into a new local repository does not fix this. The only solution I know so far is to git clone the entire remote repository (origin/master) into a new local repository. But is there any better (faster) solution?

There is Debian bug report that has last message from February 2011. Is this the same bug I have or is there already a fix or any solution or workaround to this? My git version is 1.7.10.

Answer

klogg picture klogg · Oct 13, 2012

Try these commands:

git fsck
git gc