致命:git-write-tree:构建树的错误

mal*_*lat 182 git

git pull从一个共享的git存储库做了一个,但在我尝试了之后出了点问题git revert.这是现在的情况:

$ git stash
Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx: needs merge
Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx: needs merge
Source/MediaStorageAndFileFormat/gdcmPNMCodec.cxx: needs merge
Testing/Source/DataStructureAndEncodingDefinition/Cxx/TestDS.cxx: needs merge
Utilities/socketxx/socket++/sockstream.cpp: needs merge
Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx: needs merge
Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx: needs merge
Source/MediaStorageAndFileFormat/gdcmPNMCodec.cxx: needs merge
Testing/Source/DataStructureAndEncodingDefinition/Cxx/TestDS.cxx: needs merge
Utilities/socketxx/socket++/sockstream.cpp: needs merge
Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx: unmerged (2aafac967c35fa4e77c3086b83a3c102939ad168)
Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx: unmerged (78cc95e8bae85bf8345a7793676e878e83df167b)
Source/MediaStorageAndFileFormat/gdcmImageCodec.cxx: unmerged (2524db713fbde0d7ebd86bfe2afc4b4d7d48db33)
Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx: unmerged (4bb4ba78973091eaa854b03c6ce24e8f4af9e7cc)
Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx: unmerged (ad0982b8b8b4c4fef23e69bbb639ca6d0cd98dd8)
Source/MediaStorageAndFileFormat/gdcmJPEGLSCodec.cxx: unmerged (4868371b7218c6e007fb6c582ad4ab226167a80a)
Source/MediaStorageAndFileFormat/gdcmPNMCodec.cxx: unmerged (f7a1b386b5b13b8fa8b6a31ce1258d2d5e5b13c5)
Source/MediaStorageAndFileFormat/gdcmPNMCodec.cxx: unmerged (6ce299c416fbb3bb60e11ef1e54962ffd3449a4c)
Source/MediaStorageAndFileFormat/gdcmPNMCodec.cxx: unmerged (75c8043a60a56a1130a34cdbd91d130bc9343c1c)
Testing/Source/DataStructureAndEncodingDefinition/Cxx/TestDS.cxx: unmerged (79c2843f2649ea9c87fa57662dafd899a5fa39ee)
...
fatal: git-write-tree: error building trees
Cannot save the current index state
Run Code Online (Sandbox Code Playgroud)

有没有办法重置所有这些?

谢谢

her*_*cek 539

使用:

git reset --mixed

而不是git reset --hard.你不会失去任何改变.

  • 有效的答案,但很高兴有一个解释发生了什么以及为什么这是必要的. (61认同)
  • 注意,当没有给出参数时,`--mixed`参数也是`git reset`的默认行为.[manpage](https://www.kernel.org/pub/software/scm/git/docs/git-reset.html)供参考. (29认同)
  • FWIW 我在做`git stash`时遇到了这个问题。做`git reset --mixed` 解决了它。 (3认同)

Dav*_*ala 36

这对我有用:

$ git status
Run Code Online (Sandbox Code Playgroud)

并检查你是否有 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
Run Code Online (Sandbox Code Playgroud)

将它们修复git add到每个,然后再试git stash一次.

git add app/assets/images/logo.png
Run Code Online (Sandbox Code Playgroud)

  • 这对我有用.git reset - 混合可能比世界和平更好,但如果没有对它的作用做一些解释,我就不会触及它.在我的情况下,在早期的拉动中发生了碰撞,我没注意到.由于未解决的拉动,存储失败. (5认同)

afi*_*ina 10

要跟进malat的响应,您可以通过创建补丁并在以后重新应用来避免丢失更改.

git diff --no-prefix > patch.txt
patch -p0 < patch.txt
Run Code Online (Sandbox Code Playgroud)

将补丁存储在存储库文件夹之外以确保安全.


mal*_*lat 8

我用了:

 git reset --hard
Run Code Online (Sandbox Code Playgroud)

我失去了一些变化,但这没关系.

  • 只需注意:[`git revert`](http://www.kernel.org/pub/software/scm/git/docs/git-revert.html)尝试合并过去的变化; 你正确使用`git reset`来简单地倒回时钟.不幸的是,`git stash`不适用于合并冲突. (6认同)
  • 如果您丢失更改,这不是解决方法;) (2认同)

小智 5

也许你的git存储库中有一些未合并的路径,你必须在存储之前解决.