git rebase:“错误:无法统计‘文件’:权限被拒绝”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5970879/
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 rebase: "error: cannot stat 'file': Permission denied"
提问by Ryan Lundy
I'm using git, and made a small commit followed by a large one. I decided to use git rebase
to squash the two commits together before pushing them. (I've never done this before.)
我正在使用 git,并做了一个小的提交,然后是一个大的提交。我决定git rebase
在推送它们之前使用将两个提交压缩在一起。(我以前从未这样做过。)
So I did:
所以我做了:
git rebase -i HEAD~2
git rebase -i HEAD~2
This gave me my editor, where I chose to pick the earlier commit and squash the later one. When I saved, git said:
这给了我我的编辑器,我选择选择较早的提交并压缩较晚的提交。当我保存时,git 说:
error: cannot stat 'filename': Permission denied
Could not apply sha1 for later commit... initial line of text for that commit
错误:无法统计“文件名”:权限被拒绝
无法为以后的提交应用sha1...该提交的初始文本行
Now:
现在:
- Neither commit appears when I do
git log
. git status
tells me I'm "Not currently on any branch."- One file is listed as modified and in the index, and two files are listed as untracked. My first commit had just one file (I think), and my second commit had a good dozen.
- 当我这样做时,既没有提交也没有出现
git log
。 git status
告诉我我“目前不在任何分支上”。- 一个文件被列为已修改并在索引中,两个文件被列为未跟踪。我的第一次提交只有一个文件(我认为),而我的第二次提交有很多。
What happened!? How do I fix it?
发生了什么!?我如何解决它?
采纳答案by CB Bailey
I've only ever seen this error on Windows and what it seems to mean is that something blocked git from modifying a file at the moment when it tried to a apply a patch.
我只在 Windows 上看到过这个错误,这似乎意味着当 git 尝试应用补丁时,某些东西阻止了 git 修改文件。
Windows tends to give processes exclusive access to files when it shouldn't really be necessary, in the past virus checkers have been one source of suspicion but I've never proved this conclusively.
Windows 往往会在不必要的情况下为进程提供对文件的独占访问权限,过去病毒检查程序一直是怀疑的来源之一,但我从未最终证明这一点。
Probably the easiest thing to do is to abort and try again, hoping that it doesn't happen the next time.
可能最简单的方法是中止并重试,希望下次不会发生这种情况。
git rebase --abort
You can attempt to use git apply
and knowledge of what commit git was actually trying to do before doing a git rebase --continue
but in all honesty I wouldn't recommend this. Most of the times I've seen this tried there's been a better than evens chance that something gets accidentally missed or messed up.
您可以尝试使用git apply
并了解 git 在执行之前实际尝试执行的操作,git rebase --continue
但老实说,我不推荐这样做。大多数情况下,我都看到过这种尝试,但意外遗漏或搞砸的几率比偶数都高。
回答by Cameron Wright
Try closing any programs that have the folder open, such as editors, explorer windows, command prompts, and FTP programs. This always fixes the issue for me on Windows.
尝试关闭打开文件夹的所有程序,例如编辑器、资源管理器窗口、命令提示符和 FTP 程序。这总是在 Windows 上为我解决问题。
回答by ManJan
Just close your IDE (VISUAL STUDIO/ATOM etc). It might work
只需关闭您的 IDE(VISUAL STUDIO/ATOM 等)。它可能工作
回答by Mike Ruhlin
When I see this on my machine, it's worse than just a "some process has the file open". The actual ownership of the file gets Hymaned up to the point where I (running as administrator) can only access it after rebooting.
当我在我的机器上看到这个时,这比“某个进程打开了文件”更糟糕。文件的实际所有权被提升到我(以管理员身份运行)只能在重新启动后才能访问它的程度。
Nearest I can tell, IIS is part of the problem. If I switch between two major branches that require a lot of files to modify, git will delete a file or directory (usually DLLs) while IIS is trying to do something or another with it. At this point, the IIS process automatically overwrites the file on disk with a version that's locked and appears to be owned by nobody.
我能说的最近,IIS 是问题的一部分。如果我在需要修改大量文件的两个主要分支之间切换,当 IIS 试图用它做某事时,git 将删除一个文件或目录(通常是 DLL)。此时,IIS 进程会自动覆盖磁盘上的文件,该文件的版本已锁定且似乎无人拥有。
Stopping IIS at this point doesn't do it. Best I've found out to do is to reboot, and remember to stop IIS before changing across major branches in the future.
此时停止 IIS 不会这样做。我发现最好的办法是重新启动,并记住在将来跨主要分支进行更改之前停止 IIS。
I know that doesn't really answer the question, but might be helpful to others.
我知道这并不能真正回答问题,但可能对其他人有帮助。
回答by romanlv
On Windows, it can be a TortoiseGIT process that blocks those files. Open task manager and end process TGitCache.exe.
在 Windows 上,它可以是阻止这些文件的 TortoiseGIT 进程。打开任务管理器并结束进程TGitCache.exe。
回答by imbatman
I just stumbled upon this thread of answers - this error is such a Bogus error.# error: cannot stat 'reddit/app/views/links': Permission denied
我只是偶然发现了这个答案——这个错误是一个虚假的错误。# 错误:无法统计“reddit/app/views/links”:权限被拒绝
That's all I got - when trying to merge. I read a few of the answers and then came to the realization - all I had to do was close my code editor which happens to be Atom.
这就是我所得到的 - 尝试合并时。我阅读了一些答案,然后意识到 - 我所要做的就是关闭我的代码编辑器,它恰好是 Atom。
Once closing the editor - I ran "git merge" again and boom , it worked.
关闭编辑器后 - 我再次运行了“git merge”并繁荣了,它起作用了。
What a pointless error:(
多么无意义的错误:(
回答by Muhammed Moussa
if using vscode, kill terminal and open new one. else maybe close terminal too
如果使用 vscode,请杀死终端并打开新终端。否则也可能关闭终端
回答by Crispy Ninja
This happens to me in Windows occasionally
这在 Windows 中偶尔会发生在我身上
error: cannot stat 'filename': Permission denied
错误:无法统计“文件名”:权限被拒绝
Most often I have multiple instance of bit bash open, and one of the git bash instances is in a directory that doesn't exist in the remote branch I'm pulling from.
大多数情况下,我打开了多个 bit bash 实例,其中一个 git bash 实例位于我从中提取的远程分支中不存在的目录中。
Closing all but one instance of git bash solves the issue for me.
关闭除一个 git bash 实例之外的所有实例都为我解决了这个问题。
回答by rgngl
If the IDE you use(in case you use one) might have been getting in the way as well. That's what happened to me when using QtCreator.
如果您使用的 IDE(如果您使用一个)也可能会妨碍您。这就是我在使用 QtCreator 时发生的事情。
回答by attolee
Using SourceTree in Win 10, fixed the problem by closing Atom editor.
在 Win 10 中使用 SourceTree,通过关闭 Atom 编辑器解决了该问题。
Error reproduce:
错误重现:
- In branch B, create a md file, using Atom edit it, save and commit.
- Switch to branch A, pull down new commits from server.
- Try Switch back, Opps, it says “error: cannot stat 'file': Permission denied”.
- 在分支 B 中,创建一个 md 文件,使用 Atom 对其进行编辑、保存和提交。
- 切换到分支 A,从服务器拉下新的提交。
- 尝试切换回来,Opps,它说“错误:无法统计'文件':权限被拒绝”。