fatal: bad object xxx

前端 未结 12 2099
[愿得一人]
[愿得一人] 2021-02-03 17:00

I tried reverting to a previous git commit with:

git revert xxx

I\'m now receiving this error as a response:

fatal: bad object          


        
相关标签:
12条回答
  • 2021-02-03 17:54

    I just ran into the same error (bad object [hash]) while attempting to merge from a branch my client didn't know about. (Similar to PrzeoR's case, but instead of needing a pull I needed to fetch)

    In my case I needed to run git fetch to re-sync my client to the state of the server. Posting this here in case anyone reaches this thread the same way I did and could benefit from this insight.

    git pull
    git cherry-pick [hash]
    fatal: bad object [hash]
    git fetch
    remote: Counting objects: 8, done. (etc.)
    From github.com:repo/branch
     * [new branch] branchname
    
    git cherry-pick [hash]
    [success]
    
    0 讨论(0)
  • 2021-02-03 17:56

    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...

    0 讨论(0)
  • 2021-02-03 17:57

    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).

    0 讨论(0)
  • 2021-02-03 17:58

    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.

    0 讨论(0)
  • 2021-02-03 18:01

    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(-)
    
    0 讨论(0)
  • 2021-02-03 18:02

    you need to do git fetch to get the latest commits in sync with local

    git fetch

    then do

    git revert

    0 讨论(0)
提交回复
热议问题