I tried reverting to a previous git commit with:
git revert xxx
I\'m now receiving this error as a response:
fatal: bad object
git fetch --all
The git fetch command downloads commits, files, and refs from a remote repository into your local repository.
[Edit 1, 19 Nov 2016] While this would sometimes 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.
[Edit 2, 6 May 2020] Suppose xxx
above resembles, e.g., b34789c0b0d3b137f0bb516b417bd8d75e0cb305
(a raw hash ID). If you got this from cut-and-paste, be sure that it's for this repository (it's easy to grab a hash ID from some other repository without realizing it, especially if you have multiple windows open). If you retyped it yourself, be sure there aren't any typos. If this involves submodules, make sure the submodule is up to date. See the comments on the question and some of the answers, including this one.
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?
In my case I was cherry-picking from another branch which I didn't pull, but I tried to copy commit's IDs from GH (I haven't got this on my local where I was cherry-picking).
Hope it helps ;-D
git pull
OR
git fetch origin
Reason: If the commit id which you are trying to cherry pick is not available in your local git, then there is a possible of this error.
Doing a git pull
will fix this. If this hasn't been fixed, ask the person who has shared the commit id to push the change to origin
and do a git pull
This issue can arise when there's an outdated or corrupted branch stored locally.
Deleting the file .git/refs/remotes/origin/xxx
(after making a backup!) then fetching a fresh copy from the server worked for me.
More detail at GitHub.
Objects that don't exist in the repository give that error message
E.g.:
git init
touch a
git add a
git commit -m 0
# This object is not in the repository.
git show 1111111111111111111111111111111111111111
As for what causes the problem, it is hard to say without a minimal reproducible example.
Submodule woes have given me that error once.