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?
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?
git fetch --all
The git fetch command downloads commits, files, and refs from a remote repository into your local repository.
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
I got this error while trying to cherry-pick a commit whose hash I had copied from GitHub. This commit was on a branch that I hadn't pulled, just like PrzeoR.
Unlike PrzeoR a git fetch didn't help at first because the branch had been deleted on GitHub.
Fortunately I was able to find the corresponding (closed) Pull Request and to restore the branch on GitHub.
I'm not sure how i got this error, This is the error i got.
fatal: bad object refs/remotes/origin/{branchname}
fatal: failed to run repack
Tried pruning the git repo via git gc --aggressive --prune=now. It did not help.
This branch was stale and it was not important for me so i deleted the branch folder
rm -rf .git/refs/remotes/origin/{branchname}
ran git gc
It did object Enumeration and clean successfully.
you need to do git fetch to get the latest commits in sync with local
git fetch
then do
git revert
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.
I ran into the same error when trying to cherry-pick (on A) the commit of another branch ( B). Issue was stupid, simply forgot to git push the commit (B).
The reason I ran into it was simple. I was switching back and forth between the main repository and a submodule. I tried to do a diff between one hash (in the main repository) and another that I copied from SourceTree, thinking it was an easy to get the old HEAD (I had regressed one revision to track down a regression). The old HEAD hash I grabbed was that of a submodule, and git diff was put out with me for feeding it garbage. That's how I ended up here, and that's when I realized it was operator error. If your hash is from a different repository git will scold you with this message. However, if you do feed it garbage, would it not be better to report "XXX not a revision in this repository"? It is every bit as general an error message as "bad object" and quite a bit less likely to send someone to stack overflow for answers. I wonder if the folks in the git community would accept that pull request...
As @jxramos wrote in a comment, this could be due to using a shallow clone in which case the hash you are refering might correspond to a commit which was not fetched by the shallow clone.
We got this message when migrating tests to a Gitlab CI which by default uses a shallow clone with a depth of 20.