简体   繁体   English

Git命令在OSX上需要sudo

[英]Git commands require sudo on OSX

I've moved back from my work MBP to my home MBP. 我已经从我的MBP工作回到了我的家庭MBP。 The work one allowed to run git commands without the need for sudo. 工作一个允许运行git命令而不需要sudo。 But I'm finding this is a requirement on my home machine. 但我发现这是我家用机器的要求。

I would prefer to be able to run git commands without sudo. 我宁愿能够在没有sudo的情况下运行git命令。

I looked at the git commands in /usr/bin, and they all have rwxr-xr-x (755), and are owned by root and group wheel. 我查看了/ usr / bin中的git命令,它们都有rwxr-xr-x(755),并且由root和group wheel拥有。 I suppose I could change this to rwxrwxrwx (777), but I'm wondering if there's a better way. 我想我可以将其更改为rwxrwxrwx(777),但我想知道是否有更好的方法。 I'm thinking of adding my user to the wheel group; 我想把我的用户添加到轮组; but would there be other side effects? 但会有其他副作用吗?

The permission on the git executable are fine; git可执行文件的权限很好; there is no reason you should need to change that, or change your group. 没有理由你需要改变它,或改变你的小组。

It's more likely that the permissions on your Git checkout are wrong. 您的Git结帐的权限更有可能是错误的。 If you accidentally checked it out with something like sudo git clone ssh://user@host/project.git , or at some point you performed some kind of operation in the repository that caused some files to be owned by root, git running under your account won't be able to write to those files. 如果你不小心用sudo git clone ssh://user@host/project.git检查了它,或者在某些时候你在存储库中执行了某种操作导致某些文件被root拥有, git在您的帐户将无法写入这些文件。

Most likely, what you need to do is chown -R <user> myproject in order to make your project owned by your own user account, rather than root. 最有可能的是,您需要做的是chown -R <user> myproject ,以使您的项目由您自己的用户帐户拥有,而不是root。

If you were prompted like this: 如果您被提示如下:

Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo. 同意Xcode / iOS许可证需要管理员权限,请通过sudo以root身份重新运行。

And then you ran: 然后你跑了:

sudo git init .

After updating xcode license. 更新xcode许可证后。 Just remove the init and re-init w/o sudo 只需删除init并重新初始化没有sudo

sudo rm -rf .git
git init .

This fixed my issue. 这解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM