unable to access '/Users/dida/.config/git/attr

2020-08-13 08:02发布

问题:

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

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

回答1:

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

sudo chown -R dida /Users/dida


回答2:

Cause

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

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):

/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.

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

Resolution

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

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.

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

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

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

Recompile Git using more sensible defaults:

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



回答3:

git uses the HOME and XDG_CONFIG_HOME environment settings to lookup the config files.

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

id -a

Check also git config -l --show-origin to see where Git is trying to access those config files.



回答4:

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



回答5:

Upon finding out more information on the file, I noticed the file was not owned by my user("ubuntu"), but by "root" instead.

ls -dl /home/$USER/.config to find out the user and group of the file


sudo chown $USER -R /home/$USER/.config to update the user of the file sudo chgrp $USER -R home/$USER/.config/ to update the group of the file to the your current user

Now, when you get the file details using ls again, you'll see the information was updated.

That fixed it for me.



回答6:

warning: unable to access '/Users/raavan/.config/git/ignore': Permission denied warning: unable to access '/Users/raavan/.config/git/attributes': Permission den

ok! if you had something similar, this is the solution. use sudo command

sudo git add --all, sudo git commit -m ""

this will work and worked for me in mac os.

if anyone knows why the sudo command worked or alternative way please respond!.