导致 "Permission denied"错误的 git 别名

标签 git

以下命令

$ git co -b newbranch
$ git co oldbranch

导致“fatal: cannot exec 'git-co': Permission denied”错误。

同时,

$ git checkout -b newbranch
$ git checkout oldbranch

$ sudo git co -b newbranch
$ sudo git co oldbranch

按预期工作。 .git 文件夹的所有权是为拥有主文件夹的用户设置的,0755/0644 是 .git 文件夹/子文件夹/文件的模式。系统中的任何地方都没有 git-co 脚本(这是 git-checkout 的可扩展别名,位于/usr/libexec/git-core` 目录中) .

别名在主文件夹的 .gitconfig 中定义:

[alias]
co = checkout

root 或非特权用户的 git config -l 输出没有区别。仍然 sudo git co oldbranch 有效,而 git co oldbranch 无效。

我错过了什么?

Gentoo/内核 3.0.6/git 1.7.3.4

最佳答案

这个问题的正确答案实际上是不同的。在 git 运行别名之前,它会检查 $PATH。如果目录不存在或缺少权限,git 会生成 "fatal: cannot exec 'git-co': Permission denied"。它永远不会检查别名,所以 git foobar 会产生同样的错误。

git 邮件列表中的好人还让我想起了一个 strace 工具,它可以帮助找到返回 EACCES 的条目,如:strace -f -e execve git foobar

感谢来自 git 邮件列表的 Jeff King。 :)

关于导致 "Permission denied"错误的 git 别名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7997700/

相关文章:

git - 将提交(已推送)从分支移动到新分支

git - 不支持的 URL 协议(protocol)

linux - 当我尝试添加一个文件名在 Windows 上无效的文件时,我可以让 git 警告我吗?

c# - 恢复到 Git for visual studio 2012 中的先前提交

windows - 在 Windows 下使用 ssh 克隆 github.com 的 repo 时出现 "no address associated with name"错误

git - Pip 无法再从 https 克隆 - 错误 128

git - 如何 merge 两个不相关的 git 存储库,保留历史

git - 来自 git add 的警告。与 git add * 比较

git - 如何获取 Git 将使用的 "committer"信息

git-config 风格的配置系统