I have done the classic steps to recover the blob from the FAQ but it seems there is no other copy of it anywhere that I can find (I am working alone and haven't push to the remote for a while so it's not there) so I can't recover it.

This blob is actually the first version of a file which has been modified a lot since then. I am fine losing the information about that version of the file. So I would like just to remove it from the commit that is pointing to it. How can I do that?

This question is about a corrupted tree, which is a bit different. None of these answers can help me, sadly. I am going to try a few things and will post it here if they work.
–
Cyrille KaJan 4 '13 at 2:28

1 Answer
1

Short version: I amended the commit pointing to the corrupt blob to remove it from the history.

Long version: I thought that since I knew what the file was, and just wanted to make it disappear from the commit, then I could just amend the old commit. I didn't really expect it to work, but eventually it did.

I have to point out that I removed the blob in .git/objects in trying previous things, and it is possibly important into why it worked.

First, i had to know what commit it was. For that I used the command

git log --raw --all --full-history -- subdir/my-file

I found the commit was named 966a46....

Then I did the steps to amend it. Since it was an old commit, I used

git rebase -- interactive 966a46^

My editor came in with one line for each commit, and I changed "pick" to "edit" in front of the commit I wanted to modify.

The command git status showed me that the file I wanted to erase was modified:

I'm actually not sure what it means, but this commit was supposed to be the first in which the file would appear, after the fix. So I didn't want it to be deleted, but on the contrary, added to the commit! So I did

git add subdir/my-file

And surely git status showed it as a "new file".

Then I did git rebase --continue and everything went good, and the rebase was a success.

And git gc failed too, when I asked him to prune everything. So I figured out the best course of action was, since I had successfully pushed before, to clone everything back in a new repository and work from there.