36

I am using bitbucket and git to revision a project I am currently working on. Today I tried to pull down the latest working copy of the project but was met with an error that I cant seem to find any solution to.

$ git pull
Password for 'bitbucket.org':
remote: Counting objects: 65, done.
remote: Compressing objects: 100% (31/31) done.
remote: Total 34 (delta 19), reused 0 (delta 0)
Upacking objects: 100% (34/34), done.
fatal: bad object 4324324....(etc object number)
error: https://bitbucket.org/myusername/myproject.git did not send all necessary objects

I have searched for this error "did not send all necessary objects" but there doesn't seem to be any documentation regarding this issue can anyone help please?

Zombo
  • 1
  • 62
  • 391
  • 407
Theo Kouzelis
  • 3,195
  • 5
  • 37
  • 66

16 Answers16

47

I had this issue, related to a branch. Following @fnagel's similar approach, I just deleted the following folder, and it fixed the issue:

.git/refs/remotes/origin/<name of branch>
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
SebK
  • 499
  • 4
  • 2
  • 2
    Had this issue when there was a power cut during git pull and computer shut down. This fixed the issue. Thanks – Shreehari Aug 29 '22 at 13:29
12

git pull --prune fixed the similar error message I had on a repo.

Ribens
  • 208
  • 2
  • 8
10

"did not send all necessary objects" is the manifestation of the error, not the error itself.
For information, this message comes from builtin/fetch.c method store_updated_refs(), which calls connected.c method check_everything_connected(). It performs a

git rev-list --verify-objects --stdin --not --all
/*
 * If we feed all the commits we want to verify to this command
 *
 *  $ git rev-list --verify-objects --stdin --not --all
 *
 * and if it does not error out, that means everything reachable from
 * these commits locally exists and is connected to some of our
 * existing refs.
 *
 * Returns 0 if everything is connected, non-zero otherwise.
 */

The real issue is during the unpacking phase:

Upacking objects: 100% (34/34), done.
fatal: bad object 4324324....(etc object number)

It shouldn't be tied to some BitBucket hiccup, since its status page is clear.

So it might be linked to some corruption, added during a previous push by another contributor. If any clone of that BitBucket repo from any user results in the same message, you need to contact the support for them to troubleshoot this repo.

Zombo
  • 1
  • 62
  • 391
  • 407
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
6

After deleting all contents in this holder .git/refs/remotes/origin/, the pull progress returns to normal. FYR, hope to help u.

Eathan
  • 69
  • 1
  • 1
  • 3
    Isn't this basically the same guidance as [@SebK's answer](https://stackoverflow.com/a/72040646/3025856) from April, except less specific as you're potentially deleting _all_ branch references? – Jeremy Caney Aug 06 '22 at 00:47
3

I fix this problem for myself just by deleting related branch inside .git/refs/tags/remote file. I faced with this problem for my master branch and deleting it was the solution.

Ramin Khodaie
  • 242
  • 3
  • 10
3

Delete all content from .git/refs/remotes/origin folder then run.

git pull
Nasim Alizai
  • 149
  • 10
2

I had this issue when my computer crashed while fetching a new tag. Deleting the related tags in .git/refs/tags solved the issue for me.

fnagel
  • 654
  • 4
  • 11
2

My problem was a dodgy stash. Deleted that and all good

OldBloke
  • 51
  • 6
1

in terminal open .git in your project repository and remove your bad object name

Edgar
  • 11
  • 1
  • That is potentially dangerous. Other answers are more reliable – Ivan P. Sep 22 '22 at 17:50
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 22 '22 at 17:51
1

Deleting the remote repo directory and the tag did not work for me.
I also deleted the head, which did solve the problem:

rm .git/refs/heads/master\ 2

ie

rm .git/refs/heads/<headNameHere>
SherylHohman
  • 16,580
  • 17
  • 88
  • 94
Haggishunt56
  • 39
  • 1
  • 9
0

what worked for me is deleting .git/ORIG_HEAD then doing the pull again.

mahdi komaiha
  • 61
  • 1
  • 5
0

I got the same error with go mod tidy

go.mod at revision v0.0.17: git fetch -f origin refs/heads/:refs/heads/ refs/tags/:refs/tags/ in /home/rajashrijadhav/go/pkg/mod/cache/vcs/d41284d17c2c993ecb14c1b7da80659c76c8bd6acb85aebf5e5c510f5c0f52a0: exit status 1: fatal: bad object 96809b75c6be48d79506c17403e8615e300555e6

git did not send all necessary objects

Solution that worked for me :

delete the directory : /home/rajashrijadhav/go/pkg/mod/cache/vcs/d41284d17c2c993ecb14c1b7da80659c76c8bd6acb85aebf5e5c510f5c0f52a0

and then do

go mod tidy

it works

0

Step 1: Delete your local branch.

git branch --delete <branch name>

Step 2: Delete the file

rm .git/refs/heads/<branch name>

Ravi kant
  • 89
  • 5
0

This may happen if you have invalid character in branch name. For me, it was space at the end.

Deleting related branch file from origin folder didn't work. So, I searched for that name specifically at other locations.

I found reference in origin > packed-refs file. I deleted that line from it.

After that, git gc was giving following error:

failed to run repack

So, following command did the trick:

git gc --aggressive --prune=now

Chintan Shah
  • 1,744
  • 2
  • 26
  • 28
0

I had the same problem because iCloud created a back up file, .git/refs/heads/main 2. So I just deleted the file rm -rf .git/refs/heads/main 2.

charlchad
  • 3,381
  • 1
  • 16
  • 9
0

I've gotten this error and resolved it - on a Windows box, by deleting all the [desktop.ini] files in the repo. ...and there are a bunch - luckily I'm using cygwin (Linux/Unix emulator), which makes it a 1 line [find] statement.

Hewbie
  • 1
  • Please make your answer more clear and brief. You can check https://stackoverflow.com/help/how-to-answer – SEGV Aug 30 '23 at 19:47