开发者

Git commit problem: Unable to append to .git/

开发者 https://www.devze.com 2023-03-20 01:50 出处:网络
I am unable to commit changes in my开发者_如何学C project when using git. Here is my terminal: tomas@tomas-laptop:~/menu_operations$ git commit -m \"initial commit\"

I am unable to commit changes in my开发者_如何学C project when using git.

Here is my terminal:

tomas@tomas-laptop:~/menu_operations$ git commit -m "initial commit"
error: Unable to append to .git/logs/refs/heads/7.x-1.x: Permission denied
fatal: cannot update HEAD ref

menu_operations is the name of my project.

I don't know what permission I have to allow. Can anybody help?


Check the user and permission on .git/logs/refs/heads/, maybe you ran something as root.

Explanation: when you run some git commands as root (sudo?) any new files/directories created will be owned by root, and by default[1] other users won't have write permission on these files/directories.

When you, later, work with that repository, things may appear to work, until the time that you need to write to a file that was in fact created by root, i.e. owned by root.

This should fix it, at least on linux:

 sudo chown -Rc $UID .git/

It will also show you any files that it changed owners for.

[1]in a sane setup, at least


Check the user and permission on .git/logs/refs/heads/, maybe you ran something as root.


Just wanted to add for those deploying with Capistrano that you should be working with the .git/ directories here

/var/www/rails/production/shared/git_cache/.git

and

/var/www/rails/production/current/.git

This assumes you're using these given directories and that you're pushing to production... but it should get you going in the right direction.


Linux command:

  • sudo chown -Rc $UID .git/
  • id -u {yourusername}

and the outcome: changed ownership of ‘.git/packed-refs’ from root to 1000

changed ownership of ‘.git/logs/HEAD’ from root to 1000

changed ownership of ‘.git/logs/refs/heads/master’ from root to 1000

changed ownership of ‘.git/logs/refs/remotes/origin/HEAD’ from root to 1000

changed ownership of ‘.git/logs/refs/remotes/origin/master’ from root to 1000

changed ownership of ‘.git/objects/pack/pack-b905d78889aea64ca69a61c0efaa76ba95b08786.idx’ from root to 1000

changed ownership of ‘.git/objects/pack/pack-b905d78889aea64ca69a61c0efaa76ba95b08786.pack’ from root to 1000

changed ownership of ‘.git/objects/info/packs’ from root to 1000

changed ownership of ‘.git/info/refs’ from root to 1000


use

sudo chown -R youremailid .git/


chown -R $(whoami) /usr/local.git should do it.

0

精彩评论

暂无评论...
验证码 换一张
取 消