简体   繁体   English

Git 钩子:“.git/hooks/pre-commit”:不允许操作

[英]Git hooks: '.git/hooks/pre-commit': Operation not permitted

This is all on OS X Mojave.这一切都在 OS X Mojave 上。

I'm trying to block myself from mistakenly making commits to the master branch, because that is a thing I do a little too often, using the pre-commit Git hook from this SO answer , changed slightly because I use bash instead of sh.我试图阻止自己错误地提交到 master 分支,因为这是我经常做的事情,使用这个 SO answer 中的pre-commit Git 钩子,略有改变,因为我使用 bash 而不是 sh。 Every time I tried to run it, though, I got the following:但是,每次我尝试运行它时,都会得到以下信息:

fatal: cannot exec '.git/hooks/pre-commit': Operation not permitted

I checked the permissions of the .git and .git/hooks directories.我检查了.git.git/hooks目录的权限。 Both are drwxrwxrwx .两者都是drwxrwxrwx The permissions on pre-commit itself are: pre-commit本身的权限是:

-rwxr-xr-x@  1 emeyer  staff    25 Feb  5 11:50 pre-commit

…which is the same as the pre-commit.sample file I copied over to pre-commit and then replaced the contents. ...这与我复制到pre-commit然后替换内容的pre-commit.sample文件相同。 I tried chmod +w but that didn't fix it.我试过chmod +w但这并没有解决它。

I decided to simplify my testing and replaced the contents of pre-commit with the following:我决定简化我的测试并将pre-commit的内容替换为以下内容:

#!/bin/bash

echo "Test"

I still got the above-referenced Operation not permitted error.我仍然收到上述Operation not permitted错误。 I also tried it with #!/bin/sh like in the SO answer's example;我也用#!/bin/sh尝试过,就像在 SO 答案的例子中一样; same result.同样的结果。

If I try running the script directly, by typing ./pre-commit from the command line, I get a slightly different error: -bash: ./pre-commit: /bin/bash: bad interpreter: Operation not permitted .如果我尝试直接运行脚本,通过./pre-commit输入./pre-commit ,我会得到一个稍微不同的错误: -bash: ./pre-commit: /bin/bash: bad interpreter: Operation not permitted The error is consistent whether I use /bin/bash , /bin/sh , /usr/local/bin/bash , or /usr/local/bin/sh .无论我使用/bin/bash/bin/sh/usr/local/bin/bash还是/usr/local/bin/sh ,错误都是一致的。

Googling, Binging, and SO-searching didn't get me an answer that worked, so I'm asking here how to allow the operation, or whatever is needed.谷歌搜索、Binging 和 SO-searching 没有给我一个有效的答案,所以我在这里问如何允许操作,或任何需要的东西。

The pre-commit file may have file metadata associated with it (the @ in your ls output suggests this), and that that file metadata may include the com.apple.quarantine attribute. pre-commit文件可能具有与之关联的文件元数据( ls输出中的@表明了这一点),并且该文件元数据可能包含 com.apple.quarantine 属性。

You should be able to confirm this using the following:您应该能够使用以下方法确认这一点:

ls -l@ pre-commit

or或者

xattr -l pre-commit

And you should be able to remove the attribute with:您应该能够删除该属性:

xattr -d com.apple.quarantine pre-commit

ref: https://stackoverflow.com/a/9952742/157515参考: https : //stackoverflow.com/a/9952742/157515

另请参阅:this similar issue ,其中包括其他示例和特定于某些编辑器(TextEdit 和 BBEdit)的一些答案

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

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