Git 提交问题:无法附加到 .git/
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6692292/
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 commit problem: Unable to append to .git/
提问by tomas.teicher
I am unable to commit changes in my project when using git.
使用 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.
menu_operations
是我的项目名称。
I don't know what permission I have to allow. Can anybody help?
我不知道我必须允许什么权限。有人可以帮忙吗?
回答by sehe
Check the user and permission on .git/logs/refs/heads/, maybe you ran something as root.
检查 .git/logs/refs/heads/ 上的用户和权限,也许你以 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.
说明:当您以 root 身份运行某些 git 命令(sudo?)时,创建的任何新文件/目录都将由 root 拥有,默认情况下[1] 其他用户对这些文件/目录没有写权限。
When you, later, work with that repository, things may appearto work, until the time that you need to write toa file that was in fact created by root, i.e. owned byroot.
当您稍后使用该存储库时,事情似乎可以正常工作,直到您需要写入实际上由 root 创建的文件,即由root拥有的文件。
This should fix it, at least on linux:
这应该可以解决它,至少在 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
[1]在一个健全的设置中,至少
回答by CharlesB
Check the user and permission on .git/logs/refs/heads/, maybe you ran something as root.
检查 .git/logs/refs/heads/ 上的用户和权限,也许你以 root 身份运行了一些东西。
回答by Ankit Badiya
use
用
sudo chown -R youremailid .git/
须藤 chown -R youremailid .git/
回答by Neal
Just wanted to add for those deploying with Capistrano that you should be working with the .git/ directories here
只是想为那些使用 Capistrano 部署的人添加,您应该在这里使用 .git/ 目录
/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.
这假设您正在使用这些给定的目录并且您正在推动生产......但它应该让您朝着正确的方向前进。
回答by Matthew Chen
chown -R $(whoami) /usr/local.git should do it.
chown -R $(whoami) /usr/local.git 应该这样做。
回答by adrian filipescu
Linux command:
Linux命令:
- sudo chown -Rc $UID .git/
- id -u {yourusername}
- 须藤 chown -Rc $UID .git/
- id -u {您的用户名}
and the outcome: changed ownership of ‘.git/packed-refs' from root to 1000
结果:将“.git/packed-refs”的所有权从 root 更改为 1000
changed ownership of ‘.git/logs/HEAD' from root to 1000
将“.git/logs/HEAD”的所有权从 root 更改为 1000
changed ownership of ‘.git/logs/refs/heads/master' from root to 1000
将“.git/logs/refs/heads/master”的所有权从 root 更改为 1000
changed ownership of ‘.git/logs/refs/remotes/origin/HEAD' from root to 1000
将“.git/logs/refs/remotes/origin/HEAD”的所有权从 root 更改为 1000
changed ownership of ‘.git/logs/refs/remotes/origin/master' from root to 1000
将“.git/logs/refs/remotes/origin/master”的所有权从 root 更改为 1000
changed ownership of ‘.git/objects/pack/pack-b905d78889aea64ca69a61c0efaa76ba95b08786.idx' from root to 1000
将 '.git/objects/pack/pack-b905d78889aea64ca69a61c0efaa76ba95b08786.idx' 的所有权从 root 更改为 1000
changed ownership of ‘.git/objects/pack/pack-b905d78889aea64ca69a61c0efaa76ba95b08786.pack' from root to 1000
将 '.git/objects/pack/pack-b905d78889aea64ca69a61c0efaa76ba95b08786.pack' 的所有权从 root 更改为 1000
changed ownership of ‘.git/objects/info/packs' from root to 1000
将“.git/objects/info/packs”的所有权从 root 更改为 1000
changed ownership of ‘.git/info/refs' from root to 1000
将“.git/info/refs”的所有权从 root 更改为 1000