GIT:“致命:无法写入 new_index 文件”提交时
当我尝试将更改提交到本地存储库时,我收到以下消息:
致命:无法写入 new_index 文件
When I try to commit changes to local repo, I have got following message:
fatal: unable to write new_index file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
正如这个线程所示,通常是磁盘空间问题:
中看到它
在 Git 2.46(2024 年第 3 季度)之前,第 17 批,当“
git合并
“(man) 发现索引无法刷新(例如,由于另一个进程在后台执行相同的操作),它死掉了,但是在写入MERGE_HEAD
等文件之后,这是对于从失败中恢复的目的毫无用处。请参阅 提交 2e5a636(2024 年 6 月 17 日),作者:凯尔·赵 (
yefengzkk
)。(由 Junio C Hamano --
gitster
-- 合并于 提交 6c0bfce,2024 年 6 月 27 日)这意味着,当您遇到致命错误时,您将不再看到任何错误:
.git/MERGE_HEAD
.git/MERGE_MODE
.git/MERGE_MSG
As this thread illustrates, this is usually a disk space issue:
Note: you can also see it for
Before Git 2.46 (Q3 2024), batch 17, when "
git merge
"(man) sees that the index cannot be refreshed (e.g., due to another process doing the same in the background), it died but after writingMERGE_HEAD
etc. files, which was useless for the purpose to recover from the failure.See commit 2e5a636 (17 Jun 2024) by Kyle Zhao (
yefengzkk
).(Merged by Junio C Hamano --
gitster
-- in commit 6c0bfce, 27 Jun 2024)That means, when you encounter that fatal error, you will no longer see any:
.git/MERGE_HEAD
.git/MERGE_MODE
.git/MERGE_MSG
如果您正在使用 TortoiseGit,此错误(或者最近的错误:错误:无法写入索引。)很可能是由于启用了 TortoiseGit 图标覆盖而导致的。要禁用图标覆盖,请转到:
TortoiseGit >设置>图标叠加
并将状态缓存设置为无。这可能会在 TortoiseGit 的未来版本中得到修复,但目前看来很常见。
If you are using TortoiseGit, this error (or more recently: error: Unable to write index.) is very likely caused by having TortoiseGit icon overlays enabled. To disable icon overlays, go to:
TortoiseGit > Settings > Icon Overlays
and set Status cache to None. This may be fixed in a future version of TortoiseGit, but for now it seems to be common.
当我合并 sshfs 安装的 git 存储库时,我遇到了同样的错误。任何地方都不缺乏空间。
就我而言,解决方案是向 sshfs mount 命令添加 -o workaround=rename 选项。
就像这样:
sshfs -o idmap=用户 -o uid=[lokal uid] -o gid=[lokal gid] -o 解决方法=重命名 [主机]: [挂载点]
I was getting the same error while I was merging a git repo that was sshfs mounted. There was no shortage of space anywhere.
In my case the solution was to add an -o workaround=rename option to the sshfs mount command.
Like so:
sshfs -o idmap=user -o uid=[lokal uid] -o gid=[lokal gid] -o workaround=rename [host]: [mountpoint]
我有同样的问题。就我而言,上述解决方案不起作用。
此错误背后的原因是文件
.git/index
由于某种未知原因而损坏。我只是将该文件重命名为其他名称并运行“git add”。来自 git bash 的命令并且有效。希望这对某人有帮助。
I had same problem. In my case above solutions didn't work.
The reason behind this error is that the file
.git/index
was corrupted for some unknown reason. I just renamed the file to something else and run the 'git add .' command from git bash and it worked.Hope this helps someone.
我已经找到解决方案。只需释放一些磁盘空间即可。
I have found solution. Just need to free some disk space.
对我来说这是一个文件锁定问题。
为了解决这个问题,我:
希望这有帮助!
For me it was a file locking issue.
To solve it I:
Hope this helps!
我已经遵循了这里的每个解决方案,但没有一个有效。我不缺少磁盘空间,我禁用了 Windows Defender、禁用了图标覆盖等等。我有大量文件要导入,也许这就是导致问题的原因(除其他外,我还有
boost
库)。我只是打开“Git Bash”并发出了一些
git add
和git commit
,一切都很顺利。这与 TortoiseGit 有关,但我不确定是什么。它似乎因大量文件或大目录深度而窒息。I have followed every solution here and none of them worked. I have no shortage of disk space, I have disabled Windows Defender, disabled icon overlays and whatnot. I had tons of files to import and maybe this was causing the problem (I had
boost
libraries among other things).I simply opened "Git Bash" and issued a number of
git add
and agit commit
and all went well. This has something to do with TortoiseGit but I am not sure what. It seems to choke on a large number of files or large directory depth.我使用 Cygwin 和 git-svn 遇到此错误。对我有用的解决方案是进行垃圾收集(当时看起来很奇怪):
I got this error using Cygwin and git-svn. The solution that worked for me was to do garbage collection (odd as it seemed at the time):
我遇到了这个问题,但我能够使用 msysgit 提交。我更新了 tortoisegit,还注意到我的 msysgit 版本与 tortoise git 不同步。我不确定最新版本是否修复了这个问题,或者是否是由于 Tortoise 和 msysgit 版本不同所致。无论如何,还有一件事要检查。将它们更新为后一切都开始工作
乌龟Git 1.7.10.0
git版本1.7.10.msysgit.1
I was having this issue, but I was able to commit with msysgit. I updated tortoisegit, and also noticed that my msysgit version was not in sync with tortoise git. I'm not sure if the latest version fixed it, or if it was due to having different versions of tortoise and msysgit. Anyway, another thing to check. It all started working after updating them both to
TortoiseGit 1.7.10.0
git version 1.7.10.msysgit.1
我在 macOS 上遇到了同样的问题,我通过删除
repo_folder/.git/index.lock
解决了这个问题I had the same problem on macOS, I have solved it by removing
repo_folder/.git/index.lock
我在
.git\index.lock
上使用了 Unlocker 来解锁任何句柄由其他进程保持打开状态。就我而言,它是 TgitCache.exe。I used Unlocker on
.git\index.lock
to unlock any handles that are held open by other processes. In my case it was TGitCache.exe.我在 Windows 10 中使用 git,通过清除系统的临时目录解决了这个问题。
正如这里的大多数回复所暗示的那样,这是一个与磁盘空间相关的问题。
I'm using git in Windows 10, and this issue was resolved for me by clearing the system's temp directory.
As most replies here suggest, it's a disk-space related problem.