git 错误“无法写入 sha1 文件名……权限被拒绝”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6551441/
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 error “unable to write sha1 filename … Permission denied”
提问by morpheus
I am using git on windows. This is what I did: doing development on machine M1, created bare repository on USB drive M2 to backup the repository on M1. I did backups using this command (from git bash on M1):
我在 Windows 上使用 git。这就是我所做的:在机器 M1 上进行开发,在 USB 驱动器 M2 上创建裸存储库以备份 M1 上的存储库。我使用此命令进行了备份(来自 M1 上的 git bash):
git push --mirror "f:\repo"
Worked without any issues. Then I bought a new machine M3. I cloned the repository from M2 to M3:
工作没有任何问题。然后我买了一台新机器M3。我将存储库从 M2 克隆到 M3:
git clone "f:\repo" .
Made some checkins to the repo in M3. Then I did (from git bash on machine M3)
对 M3 中的 repo 进行了一些检查。然后我做了(来自机器 M3 上的 git bash)
git push --mirror "f:\repo"
I get this error: unable to write sha1 filename … Permission denied How can I fix this?
我收到此错误:无法写入 sha1 文件名...权限被拒绝 我该如何解决?
回答by VonC
Even if it is about a different context (git+ssh), check the ACL associated with your repo.
See for instance this blog post.
即使它是关于不同的上下文 (git+ssh),请检查与您的 repo 关联的 ACL。
例如,请参阅此博客文章。
As suggested in the SO question "Git pull error: unable to create temporary sha1 filename" (which has other interesting suggestions as well), try redoing your bare repo, this time with the config:
正如 SO 问题“ Git pull 错误:无法创建临时 sha1 文件名”(还有其他有趣的建议)中的建议,尝试重做您的裸仓库,这次使用配置:
git config core.sharedRepository true
回答by A_toaster
Bit late but none of these worked for me. I had to run sudo git gc
in the remote repository and that somehow fixed all my problems.
有点晚了,但这些都不适合我。我不得不sudo git gc
在远程存储库中运行,这以某种方式解决了我的所有问题。
After that I pushed again and it worked
之后我再次推,它起作用了
回答by Pipo
Ran into this error because of permissions on distant respository. In my case it was the ssh user which was the wrong one for rights.
由于远程存储库的权限而遇到此错误。在我的情况下,是 ssh 用户在权利方面是错误的。
回答by Kemin Zhou
My particular error messages:
我的特定错误消息:
error: unable to write sha1 filename ./objects/ee/7ed0ef8db273d8d0acef46f3cc8ad0ae140d50: Permission denied
I just fixed my problem. It turned out to be the repository issue. In the /GIT/HOME/projectdir/objects/
我刚刚解决了我的问题。结果证明是存储库问题。在 /GIT/HOME/projectdir/objects/
doing ls you should see a lots of directories with 2 letters:
做 ls 你应该看到很多带有 2 个字母的目录:
00 0a 14 1e 28 32 3c 46 50 5a 64 6e 78 82 8c 96 a0 aa b4 be c8 d2 dc e6 f0 fa
01 0b 15 1f 29 33 3d 47 51 5b 65 6f 79 83 8d 97 a1 ab b5 bf c9 d3 dd e7 f1 fb
02 0c 16 20 2a 34 3e 48 52 5c 66 70 7a 84 8e 98 a2 ac b6 c0 ca d4 de e8 f2 fc
03 0d 17 21 2b 35 3f 49 53 5d 67 71 7b 85 8f 99 a3 ad b7 c1 cb d5 df e9 f3 fd
04 0e 18 22 2c 36 40 4a 54 5e 68 72 7c 86 90 9a a4 ae b8 ... (many others removed) info pack
Here I just list a few for example (ee that trigger the error message is one of them). ls -l will show some directories got -r read only permission. using the git account do chmod -R +w on those directories missing the w label solved my problem. In my case several directories including 'ee' missed the write permission.
这里我只列举几个例子(触发错误信息的ee就是其中之一)。ls -l 将显示一些目录获得了 -r 只读权限。在那些缺少 w 标签的目录上使用 git 帐户 do chmod -R +w 解决了我的问题。在我的例子中,包括“ee”在内的几个目录没有写权限。
回答by Jamie Edwards
We ran into this issue when a colleague did not have the correct umasksetting in his .bashrcthat caused any files he committed to be set as read only for the rest of us trying to write changes to that same file in the git repo.
当一位同事在他的.bashrc中没有正确的umask设置导致他提交的任何文件被设置为只读时,我们遇到了这个问题,我们其他人试图将更改写入 git repo 中的同一文件。
You can setup umask in /etc/bashrc or /etc/profile file for all users. By default most Linux distro set it to 0022 (022) or 0002 (002). Open /etc/profile or ~/.bashrc file, enter:
您可以在 /etc/bashrc 或 /etc/profile 文件中为所有用户设置 umask。默认情况下,大多数 Linux 发行版将其设置为 0022 (022) 或 0002 (002)。打开 /etc/profile 或 ~/.bashrc 文件,输入:
# vi /etc/profile
OR
或者
$ vi ~/.bashrc
Append/modify following line to setup a new umask:
追加/修改以下行以设置新的 umask:
umask 022
Save and close the file. Changes will take effect after next login. All UNIX users can override the system umask defaults in their /etc/profile file, ~/.profile (Korn / Bourne shell) ~/.cshrc file (C shells), ~/.bash_profile (Bash shell) or ~/.login file (defines the user's environment at login).
保存并关闭文件。更改将在下次登录后生效。所有 UNIX 用户都可以覆盖其 /etc/profile 文件、~/.profile(Korn / Bourne shell)、~/.cshrc 文件(C shell)、~/.bash_profile(Bash shell)或 ~/.login 中的系统 umask 默认值文件(定义用户登录时的环境)。
Here is a link explaining umask permissions
这是一个解释 umask 权限的链接
回答by Pipper Tetsing
I had this issue during 2 days and i finally figured out a way to solve it. The error occurs because the branch (in the remote repository) you actually wanna push into is currently checked out. When applying the --mirror
or --all
option, at least a branch is checked out, therefore the permission denied.
我在 2 天内遇到了这个问题,我终于找到了解决它的方法。发生错误是因为您实际想要推入的分支(在远程存储库中)当前已签出。应用--mirror
or--all
选项时,至少会签出一个分支,因此权限被拒绝。
So just switch to another branch on the remote and apply the push
locally and this time it will work.
所以只需切换到远程的另一个分支并在push
本地应用,这次它会起作用。
回答by dulon
I too get the same error but usually when doing a "git pull" using bash on windows machine.
我也遇到同样的错误,但通常在 Windows 机器上使用 bash 执行“git pull”时。
For me, its related to some other application (usually a virus checker in my case) causing conflicts by holding onto the .git directory.
对我来说,它与其他一些应用程序(在我的情况下通常是病毒检查程序)有关,通过保留 .git 目录导致冲突。
I can usually do "git pull" a few more times and it will eventually work (after failing with same permission denied error on a different hash value) or if I'm feeling in a hurry, I would stop my virus checker, do the git pull (which would work successfully first time without the permission error) and then very quickly switch the virus checker back on again.
我通常可以多做几次“git pull”,它最终会起作用(在不同的哈希值上出现相同的权限被拒绝错误失败后)或者如果我觉得很匆忙,我会停止我的病毒检查程序,做git pull(第一次成功运行,没有权限错误),然后很快再次打开病毒检查器。
回答by Adam Brouhard
I had this same problem and was able to fix it by going to the C:\Program Files\Git
then right click on git-bash.exe
-> properties -> Compatibility -> Run this program as an Administrator.
我遇到了同样的问题,并且能够通过C:\Program Files\Git
然后右键单击git-bash.exe
-> 属性 -> 兼容性 -> 以管理员身份运行此程序来修复它。