James A. Anderson James A. Anderson - 18 days ago 10
Git Question

fatal: bad object xxx

I tried reverting to a previous git commit with:

git revert xxx


I'm now receiving this error as a response:

fatal: bad object xxx


What am I doing wrong? How do I fix this?

Answer

[Edit, 19 Nov 2016] While this would normally indicate repository corruption, it turns out to occur on Windows when some command—usually, another Git in another task—is holding internal files open and locked. In this case, terminating the other task should fix it. Original answer is below.


bad object with some hexadecimal number tends to mean that a tag has an invalid reference number in it, but can also occur for a few other strange cases. For instance, if I do a:

$ git tag foo
$ vi .git/refs/tags/foo

and change the last character (in this case from 6 to 5) and write that out:

$ git log foo
fatal: bad object foo

What exactly is the xxx here and where did it come from?