git commit stopped working - Error building trees

后端 未结 11 1201
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-23 16:13

I can not commit a change:

$ git commit
error: invalid object 100644 13da9eeff5a9150cf2135aaed4d2e337f97b8114 for \'spec/routing/splits_routing_spec.rb\'
err         


        
相关标签:
11条回答
  • 2020-12-23 16:18

    For me it was just permissions issue. When I run with sudo, it worked. perhaps something to do with mac environment

    0 讨论(0)
  • 2020-12-23 16:26

    In my case, this was due to a different version of git. I had been using my repository through the official Windows port of git and started using the MinGW port with the same version number.

    I started to encounter this issue when trying to commit with MinGW git. Switching back to windows Git solved the issue.

    0 讨论(0)
  • 2020-12-23 16:27

    This error means that you have a file with hash 13da9eeff5a9150cf2135aaed4d2e337f97b8114, and this hash is not present in .git/objects/../, or it's empty. When this error occurred, I only had this hash in the error, without the file path. Then I tried to do git gc --auto and git reset --hard. After one of these commands (these commands did not fix my problem), I got the path of the file that triggers the error.

    You just need to generate the object hash:

    git hash-object -w spec/routing/splits_routing_spec.rb
    

    For more information see documentation. In the documentation, there is an additional way of repairing this error.

    P.S. This was the only way that was helpful for me.

    0 讨论(0)
  • 2020-12-23 16:30

    You might have a corrupted object in your git repository.

    If you have a remote, or other clones of this repository, you could grab from there the problematic file and just replace it on your local repo.

    The file you want would be in:

    /repo/.git/objects/13/da9eeff5a9150cf2135aaed4d2e337f97b8114
    
    0 讨论(0)
  • 2020-12-23 16:30

    This can be caused by some third-party synchronization APP such as Dropbox and Jianguoyun. There might be two ways based on my experience:

    1. You can try to undo recent synchronization operations.
    2. Remove the related files from the folder, commit, and then move back the files.
    0 讨论(0)
  • 2020-12-23 16:32

    In my case, it is the file in remote branch that is broken. I solved it by:

    1. remove the remote branches at all by $ git remote rm origin
    2. add the remote back again: $ git remote add origin <the-remote-url>
    3. fetch the remote again: $ git fetch origin
    4. reset-hard to the desired branch on origin (say, develop): $ git reset --hard origin/develop

    Then everything goes back to normal.

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