Git Checkout 警告:无法取消链接文件,权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7199496/
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 Checkout warning: unable to unlink files, permission denied
提问by Paragon
I am aware that there are similar issues about git relating to the 'unable to unlink' warning, but I have not been able to use them.
我知道 git 存在与“无法取消链接”警告相关的类似问题,但我无法使用它们。
The main difference is that this happened when I have not been dealing with submodules in any way (I have never dealt with them before). I created a branch called 'upgrade', deleted my old framework files, and copied in the new ones. I used git add -A, then committed everything. When I tried to checkout the trunk branch, it responded with the following errors:
主要区别在于,这是在我没有以任何方式处理子模块时发生的(我以前从未处理过它们)。我创建了一个名为“升级”的分支,删除了我的旧框架文件,并复制了新的框架文件。我使用了 git add -A,然后提交了所有内容。当我尝试检出主干分支时,它响应以下错误:
warning: unable to unlink requirements/views/sk/index.php: Permission denied
warning: unable to unlink requirements/views/sv/index.php: Permission denied
warning: unable to unlink requirements/views/zh/index.php: Permission denied
warning: unable to unlink requirements/views/zh_cn/index.php: Permission denied
warning: unable to unlink requirements/views/zh_tw/index.php: Permission denied
...etc. There are hundreds of them.
...等等。有数百个。
At first I thought this was simply a permissions problem, and so I added group write permissions to the entire requirements directory recursively, but there was no change.
一开始我以为这只是权限问题,于是递归的给整个requirements目录添加了组写权限,但是没有任何变化。
Edit: As suggested in an answer below, I attempted to do the same thing but with everything else closed. I had no more luck than before.
编辑:正如下面的答案中所建议的,我尝试做同样的事情,但其他一切都关闭了。我没有比以前更多的运气了。
This issue is particularly debilitating as I cannot move to trunk to get back to normal development.
这个问题特别令人衰弱,因为我无法移动到主干以恢复正常开发。
采纳答案by VonC
I usually see that kind of error when there is a process not releasing the handle of those files.
当进程没有释放这些文件的句柄时,我通常会看到这种错误。
Make sure nothing is running, and then try your checkout again.
确保没有任何东西在运行,然后再次尝试结帐。
Note: it can also be related with the way Git has been installed (on Windows, UAC can generate problem if msysgit is installed in C:\Program
or C:\Program Files
, see "msysgit - sh.exe - fork: Permission denied - Vista 64 bit" and comment 2 of issue 437)
注意:它也可能与 Git 的安装方式有关(在 Windows 上,如果 msysgit 安装在C:\Program
或 中C:\Program Files
,UAC 可能会产生问题,请参阅“ msysgit - sh.exe - fork:权限被拒绝 - Vista 64 位”和注释 2第 437 期)
Note: as illustrated below, a common other cause of the problem is rights issue on the directory (wrong owner), not necessarily on the file that can't be unlinked.
注意:如下图所示,问题的另一个常见原因是目录(错误所有者)的权限问题,不一定是无法取消链接的文件。
回答by Elijah Lynn
In my first encounter with this error my user had rights to "write" to the file but not the containing directory. Check the permissions of the directory containing the file.
在我第一次遇到此错误时,我的用户有权“写入”文件,但不能“写入”包含目录。检查包含该文件的目录的权限。
回答by rtconner
"Unlink" essentially means "delete file" in this case.
在这种情况下,“取消链接”本质上意味着“删除文件”。
This error is not caused by git itself. You should have similar errors deleting those files manually, in a command line or file explorer.
这个错误不是由 git 本身引起的。您应该在命令行或文件资源管理器中手动删除这些文件时遇到类似的错误。
回答by Vince Yuan
You don't have the access permission, maybe because you are not the owner.
您没有访问权限,可能是因为您不是所有者。
Fix by changing the owner to yourself:
通过将所有者更改为您自己来修复:
sudo chown -R your_login_name /path/to/folder
回答by Rob Erskine
I was having the issue with a default-settings.php file in drupal 7. In this case I wasn't able to delete it or revert it just like @rtconner said. I didn't have an application or anything using this file, and it ended up being a permissions error.
我在 drupal 7 中遇到了 default-settings.php 文件的问题。在这种情况下,我无法像@rtconner 所说的那样删除或恢复它。我没有使用此文件的应用程序或任何东西,结果是权限错误。
I added chmod 777 *
to the folder and then I was able to revert it no problem.
我添加chmod 777 *
到文件夹中,然后我能够恢复它没问题。
回答by Rajendra kumar Vankadari
You can change the write permissions to get it done.
您可以更改写入权限来完成它。
sudo chmod -R ug+w .
This command will give 'w'
permissions to all the folders in the current directory.
此命令将授予'w'
对当前目录中所有文件夹的权限。
回答by Learn OpenGL ES
I ran into this problem whenever running "git repack" or "git gc" on my OS X machines, even when running git with admin privileges, and I finally solved it after coming across this page: http://hints.macworld.com/comment.php?mode=view&cid=1734
每当在我的 OS X 机器上运行“git repack”或“git gc”时,我都会遇到这个问题,即使是在以管理员权限运行 git 时,我终于在看到这个页面后解决了这个问题:http: //hints.macworld.com /comment.php?mode=view&cid=1734
The fix is to open a terminal, go to your git repo, cd into the .git folder, and then do:
修复方法是打开一个终端,转到您的 git 存储库,将 cd 放入 .git 文件夹,然后执行以下操作:
chflags -R nouchg *
If that was the issue, then after that, your git commands will work as normal.
如果那是问题所在,那么在那之后,您的 git 命令将正常工作。
回答by Hesam
To those who are using Intellij, as @rtconner said this problem is not caused by git. Since your IDE is locked a file(s) git cannot un-link it. So, you need to close your IDE and then try to merge (or whatever you like) it via command line.
对于那些使用Intellij 的人,正如@rtconner 所说,这个问题不是由 git 引起的。由于您的 IDE 被锁定,git 无法取消链接文件。因此,您需要关闭 IDE,然后尝试通过命令行合并(或任何您喜欢的)它。
回答by davetapley
This can also occur when:
这也可能发生在:
You ran a process inside a Docker container, and:
Some files were generated by that process, and:
The destination of the files is mounted as a volume on the Docker host, and:
You are running
git
on the Docker host.
您在Docker 容器内运行了一个进程,并且:
该过程生成了一些文件,并且:
文件的目的地作为卷挂载在 Docker 主机上,并且:
您正在
git
Docker 主机上运行。
If this is the case, stage the files you wish to commit and run:
如果是这种情况,请暂存您希望提交并运行的文件:
git diff --name-only --cached | xargs ls -l
Files which meet the above criteria will be prefixed with:
符合上述条件的文件将以:
-rw-r--r-- 1 root root ...
They are owned by root
and not writable, which is not good.
To fix that run:
它们归所有者所有root
且不可写,这不好。要修复该运行:
git diff --name-only --cached | xargs -i sh -c 'sudo chown $USER:$USER {}; chmod +w {}'
A cleaner solution would probably be to use the --user
option, see this for Dockerand this for Docker compose.
更简洁的解决方案可能是使用该--user
选项,请参阅Docker和Docker compose 的this。
回答by Henrik N
I had this error inside a virtual machine (running Ubuntu), when I tried to do git reset --hard
.
当我尝试在虚拟机(运行 Ubuntu)中执行git reset --hard
.
The fix was simply to run git reset --hard
from the OS X host machine instead.
修复只是git reset --hard
从 OS X 主机运行。