无法访问“/Users/dida/.config/git/attributes”:权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45204413/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:49:55  来源:igfitidea点击:

unable to access '/Users/dida/.config/git/attributes': Permission denied

gitpermissions

提问by Jing Lan

When I do some git operations, such as 'git diff' or 'git add .', it shows that warning:

当我执行一些 git 操作时,例如 ' git diff' 或 ' git add .',它显示警告:

unable to access '/Users/dida/.config/git/attributes': Permission denied 

I wonder which config I did wrong and how can I fix it?
It's better with some commands, I am using mac command line

我想知道我做错了哪个配置,我该如何解决?
使用一些命令会更好,我使用的是 mac 命令行

回答by phd

Seems you've run sudo -Hand sudo changed the ownership of some files to root. Take the files back:

似乎您已经运行sudo -H并且 sudo 将某些文件的所有权更改为root. 取回文件:

sudo chown -R dida /Users/dida

回答by Ria Anggraini

Cause

原因

Git reads config settings from a variety of paths and the doesn't have access to some of them.

Git 从各种路径读取配置设置,并且无法访问其中的一些。

Git tries to read root config setting instead of config settings due to the starting script using su command with do not reset environment variables option (-m):

由于使用 su 命令和不重置环境变量选项 (-m) 的启动脚本,Git 尝试读取根配置设置而不是配置设置:

/bin/su -m $USER -c "cd $BASE/logs && $BASE/bin/startup.sh &> /dev/null"

Bitbucket Server is being started as root with /etc/init.d/atlbitbucket start script. Since the init.d script calls start-bitbucket.sh which uses su -m this causes the environment variables for root to be preserved and atlbitbucket does not have permission to write in the root home directory.

Bitbucket Server 以 root 身份使用 /etc/init.d/atlbitbucket 启动脚本启动。由于 init.d 脚本调用使用 su -m 的 start-bitbucket.sh,这会导致 root 的环境变量被保留,并且 atlbitbucket 没有在 root 主目录中写入的权限。

Git was compiled from source using the default settings which prevents any users other than the one that compiled Git from running it

Git 是使用默认设置从源代码编译的,这会阻止除编译 Git 的用户之外的任何用户运行它

Resolution

解析度

Fix the permissions on the files and directories with regard to the Bitbucket Server user performing the command:

修复执行命令的 Bitbucket Server 用户对文件和目录的权限:

chown <USER>.<GROUP> -R /home/<USER>/.config
chown <USER>.<GROUP> -R /home/<USER>/.gitconfig

(info) Change the USER.GROUP by your username and group in your OS.

(信息)在您的操作系统中通过您的用户名和组更改 USER.GROUP。

If Bitbucket Server starting script have su command, make sure that the option -m is not used.

如果 Bitbucket Server 启动脚本有 su 命令,请确保未使用选项 -m。

If Bitbucket Server is being started with /etc/init.d/atlbitbucket start switch to starting Bitbucket Servering with service atlbitbucket start

如果使用 /etc/init.d/atlbitbucket start 启动 Bitbucket Server,请切换到使用 service atlbitbucket start 启动 Bitbucket Servering

To have Bitbucket Server automatically start at boot, run chkconfig atlbitbucket on

要让 Bitbucket Server 在启动时自动启动,请运行 chkconfig atlbitbucket on

Recompile Git using more sensible defaults:

使用更合理的默认值重新编译 Git:

make prefix=/usr/local/git all
make prefix=/usr/local/git install

or maybe this articles could help you https://confluence.atlassian.com/bitbucketserverkb/permission-denied-on-git-config-file-779171763.html

或者也许这篇文章可以帮助你https://confluence.atlassian.com/bitbucketserverkb/permission-denied-on-git-config-file-779171763.html

回答by 50chickens

try sudo -u user --set-home git clone http://github.com/repoherethis worked for me.

试试 sudo -u user --set-home git clone http://github.com/repohere这对我有用。

回答by VonC

git uses the HOMEand XDG_CONFIG_HOMEenvironment settings to lookup the config files.

git 使用HOMEXDG_CONFIG_HOME环境设置来查找配置文件。

Make sure they are set properly, to your current user (check the result of the idcommand)

确保它们已正确设置为您当前的用户(检查id命令的结果)

id -a

Check also git config -l --show-originto see whereGit is trying to access those config files.

检查还git config -l --show-origin看到其中的Git试图访问这些配置文件。