fatal: bad object xxx

I don't know the exact reason why that happens. For me, it's because I forget to pull the entire repository to my local. I have 2 or more path, and each path pulls from different branch

/path/branch_a/ -> pulled from branch A
/path/branch_b/ -> pulled from branch B

on branch A, I made a few modification, and commit as usual. I want that commit (for example the commit ID is abcdef123) appears on branch B, so I use

$ cd /path/branch_b/
$ git branch
  master
  branch_a
* branch_b 

$ git cherry-pick abcdef123

This gives me that kind of error. So I need to pull the entire repository before getting that commit

$ git pull
remote: Counting objects: 257, done.
remote: Compressing objects: 100% (58/58), done.
remote: Total 216 (delta 187), reused 186 (delta 158)
Receiving objects: 100% (216/216), 53.13 KiB | 43 KiB/s, done.
Resolving deltas: 100% (187/187), completed with 38 local objects.
From github.com:username/my_repo
   abcdef3..80c0d68  branch_a    -> origin/branch_a
Already up-to-date.

$ git cherry-pick abcdef123 
[branch_b ccddeef] Some commit message
1 file changed, 1 insertion(+), 1 deletion(-)

[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

Tags:

Git