Git“致命:无法写入新的索引文件”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16064513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git 'fatal: Unable to write new index file'
提问by Jeff
I've seen many of the other threads about this and they don't help.
我已经看过许多其他关于此的主题,但它们无济于事。
I have a very simple repo - two JavaScript files. I have 100+ GB on Macbook. When I try to move the files into a subdirectory and stage locally the changes I get ...
我有一个非常简单的 repo - 两个 JavaScript 文件。我在 Macbook 上有 100+ GB。当我尝试将文件移动到子目录并在本地暂存时,我得到的更改...
fatal: Unable to write new index file
致命:无法写入新的索引文件
This happens whether I do all actions in terminal or if I use a GUI like SourceTree. Additionally, one of the files becomes locked and I cannot delete the working directory until I log off and back in.
无论我是在终端中执行所有操作还是使用像 SourceTree 这样的 GUI,都会发生这种情况。此外,其中一个文件被锁定,在我注销并重新登录之前,我无法删除工作目录。
Why is this happening? Is the lock preventing something from staging? If so, what/how do I unlock the problem file on OS X?? The remote repo is Google Code, if that makes a difference, though I am not pushing to the remote yet. Everything is local.
为什么会这样?锁是否阻止了某些东西上演?如果是这样,我如何/如何在 OS X 上解锁问题文件?远程仓库是 Google 代码,如果这有区别的话,虽然我还没有推送到远程。一切都是本地的。
回答by Alexander Bird
In my case, the disk ran out of space, so I had to delete files from the hard drive to make space.
就我而言,磁盘空间不足,因此我不得不从硬盘驱动器中删除文件以腾出空间。
回答by theatlasroom
I've been having this same problem for the last few days. Basically, without my knowledge the entire repo had been moved to a new filesystem, when I tried to run git status, it was suddenly reporting that every file in the repo had been udpated.
最近几天我一直有同样的问题。基本上,在我不知情的情况下,整个 repo 已移至新文件系统,当我尝试运行 git status 时,突然报告该 repo 中的每个文件都已更新。
Possible solutions
可能的解决方案
So, after much google scouring, I tried the following:
所以,经过大量的谷歌搜索,我尝试了以下方法:
- changing .git permssions (same issue)
- changing .git/index permissions (same issue)
- git add-ing all the changes to commit (same issue)
- git rm-ing deleted files, since they were reporting file name too long errors (same issue)
- git reset (soft|Head|Hard) (same issue)
- git clean (same issue)
- turning off windows defender (same issue)
- updating git (same issue)
- different git clients (i use gitbash) (same issue)
- drinking 2 coffees instead of 1 (same issue)
- 更改 .git 权限(相同问题)
- 更改 .git/index 权限(相同问题)
- git 添加要提交的所有更改(相同问题)
- git rm-ing 删除了文件,因为他们报告了文件名太长的错误(同样的问题)
- git reset (soft|Head|Hard) (同样的问题)
- git clean (同样的问题)
- 关闭 Windows Defender(同样的问题)
- 更新git(同样的问题)
- 不同的 git 客户端(我使用 gitbash)(同样的问题)
- 喝 2 杯咖啡而不是 1 杯(同样的问题)
tl:dr - dirty solution
tl:dr - 肮脏的解决方案
The only thing that managed to solve the issue was to copy the index file, delete the original and rename the copy.
设法解决问题的唯一方法是复制索引文件,删除原始文件并重命名副本。
I know its not really a 'solution' but now its magically working ><, with all files / branches intact. If anyone knows why this might have work, do tell.
我知道它不是真正的“解决方案”,但现在它神奇地工作 ><,所有文件/分支都完好无损。如果有人知道为什么这可能有用,请告诉。
回答by user2465454
I had the same issue on a Mac. It seems to be caused by filesystem ACLs. Try chmod -RN /path/to/repo
to clear the ACLs. After doing this I was able to commit changes. Using the trick to copy the index file, delete the original and move the copy back achieved the same result.
我在 Mac 上遇到了同样的问题。这似乎是由文件系统 ACL 引起的。尝试chmod -RN /path/to/repo
清除 ACL。这样做后,我能够提交更改。使用技巧复制索引文件,删除原始文件并将副本移回获得相同的结果。
回答by tonymayoral
In my case, pausing dropbox sync solved the issue
就我而言,暂停 Dropbox 同步解决了这个问题
回答by Cornchip
If you have your github setup in some sort of online syncing service, such as google drive or dropbox, try disabling the syncing as the syncing service tries to read/write to the file as github tries to do the same, leading to github not working correctly.
如果您在某种在线同步服务(例如 google drive 或 dropbox)中设置了 github,请尝试禁用同步,因为同步服务会在 github 尝试读取/写入文件时尝试读取/写入文件,从而导致 github 无法正常工作正确。
回答by gls123
It happened to me that the file .git/index was in use by another process (my local development web server). I shut down the process and then it worked.
我碰巧文件 .git/index 正在被另一个进程(我的本地开发 Web 服务器)使用。我关闭了这个过程,然后它就起作用了。
回答by ForTheWin
This worked for me:
这对我有用:
rm -f ./.git/index.lock
回答by Md. Alim Ul Karim
In my case, the solution was only adding permission to the new user.
就我而言,解决方案只是向新用户添加权限。
When I installed new OS, moved my repos around and it was showing this exact error I selected the root folder and then added authenticated the user to check all
当我安装新操作系统时,移动了我的存储库,它显示了这个确切的错误,我选择了根文件夹,然后添加了经过身份验证的用户以检查所有
回答by Spyryto
Closing Visual Studio Code (that in my case has an auto-uploader background job running on file-save) solved the issue for me.
关闭 Visual Studio Code(在我的情况下有一个在文件保存时运行的自动上传后台作业)为我解决了这个问题。
Credit for the solution: my friend and colleague Arnel.
解决方案的功劳:我的朋友和同事 Arnel。
回答by Tim
I had ACL (somehow) attached to all files in the .git folder.
我将 ACL(以某种方式)附加到 .git 文件夹中的所有文件。
Check it with ls -le
in the .git folder.
ls -le
在 .git 文件夹中检查它。
You can remove the ACL with chmod -N
(for a folder/file) or chmod -RN
(recursive)
您可以使用chmod -N
(对于文件夹/文件)或chmod -RN
(递归)删除 ACL