fatal: git-write-tree: error building trees

前端 未结 6 1230
面向向阳花
面向向阳花 2020-12-12 09:55

I did a git pull from a shared git repository, but something went really wrong, after I tried a git revert. Here is the situation now:



        
相关标签:
6条回答
  • 2020-12-12 10:21

    This happened for me when I was trying to stash my changes, but then my changes had conflicts with my branch's current state.

    So I did git reset --mixed and then resolved the git conflict and stashed again.

    0 讨论(0)
  • 2020-12-12 10:24

    I used:

     git reset --hard
    

    I lost some changes, but this is ok.

    0 讨论(0)
  • 2020-12-12 10:29

    This worked for me:

    Do

    $ git status
    

    And check if you have Unmerged paths

    # Unmerged paths:
    #   (use "git reset HEAD <file>..." to unstage)
    #   (use "git add <file>..." to mark resolution)
    #
    #   both modified:      app/assets/images/logo.png
    #   both modified:      app/models/laundry.rb
    

    Fix them with git add to each of them and try git stash again.

    git add app/assets/images/logo.png
    
    0 讨论(0)
  • 2020-12-12 10:31

    Use:

    git reset --mixed

    instead of git reset --hard. You will not lose any changes.

    0 讨论(0)
  • 2020-12-12 10:37

    To follow up on malat's response, you can avoid losing changes by creating a patch and reapply it at a later time.

    git diff --no-prefix > patch.txt
    patch -p0 < patch.txt
    

    Store your patch outside the repository folder for safety.

    0 讨论(0)
  • 2020-12-12 10:41

    maybe there are some unmerged paths in your git repository that you have to resolve before stashing.

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