致命:git-write-tree:构建树时出错


202

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

有办法重置所有这些吗?

谢谢

Answers:


566

用:

git reset --mixed

代替git reset --hard。您将不会丢失任何更改。


29
请注意,当未提供参数时,该--mixed参数也是git reset默认行为。手册页以供参考。
Christopher

62
有效答案,但是对发生的事情以及为什么这样做有一个很好的解释。
mmigdol 2014年

1
@mmigdol是的-我想解释git reset一下为什么(default)--mixed选项在这里也是合适和有效的。根据merge-Git未合并路径的问题这将切换到HEAD,并告诉git忘记任何合并冲突,并保持工作目录不变。 伊拉克利翁,这是怎么回事?
nealmcb

1
@writofmandamus月晚,但请注意重置和连字符之间的空格。
Mike Ortiz

2
FWIW我在做的时候遇到了这个问题git stash。这样做git reset --mixed解决了。
亲爱的

44

这为我工作:

$ git status

并检查你是否有 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

将它们固定git add在每个位置上,然后重试git stash

git add app/assets/images/logo.png

6
这对我有用。git reset --mixed可能比世界和平还要好,但是如果不作任何解释,我不会动摇它。就我而言,我没有注意到之前的拉力发生了碰撞。由于未解决的拉动,存储失败。
伊恩·奥尔曼

我对这种策略没有更好的了解git reset --mixed,但是它可以奏效,并且似乎更适合我的情况,因为我在git stash而不是之后得到了错误git revert
火星

合并的路径表示您已运行git merge,或等效于git merge,它尝试将两个不同的更改集合并到该文件,但失败了。
siddhantsomani

11

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

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

为了安全起见,请将补丁存储在存储库文件夹之外。


这给了我:SDGL132d9f4b4:glitch-common dstromberg $ patch -p0 </tmp/patch.txt patch:****在补丁输入中仅发现垃圾。
dstromberg

我认为您应该mv将补丁重新回到创建它的目录中。1. git diff2. mv patch.txt /tmp3. git stash4. mv /tmp/patch.txt .5.patch -p0
yunzen

9

我用了:

 git reset --hard

我丢失了一些更改,但是没关系。


6
请注意:git revert尝试合并过去的更改;您已经正确地使用git reset了倒带时钟。不幸的是,这git stash不适用于合并冲突。

2
如果您丢失更改,那不是解决方法;)
PedroMagalhães18'Apr

5

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


1
这对我有帮助,所以我给它+1。但我提出了一个更广泛的答案。
David Rz Ayala 2014年

-1

当我尝试隐藏我的更改时,这发生在我身上,但是后来我的更改与分支的当前状态发生冲突

所以我做到了git reset --mixed,然后解决了git冲突并再次隐瞒。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.