使用 git 合并后修复权限
在我工作的一台服务器上,我们必须以 root 身份登录(由于原因我不会在这里讨论)。我们设置了一个用于 Web 服务器的 git 存储库,但由于文件是作为 root 创建的,因此 git 修改的文件具有错误的权限。
我创建了一个非常简单的合并后挂钩,我认为它可以解决问题。
#!/bin/bash
. git-sh-setup
chown -R www-data:www-data $GIT_DIR
我将其放入具有执行权限的 .git/hooks/post-merge 中,但该文件似乎从未运行。这是我第一次尝试设置挂钩,所以也许我遗漏了一些明显的东西。
我注意到的一件事是大多数钩子都有一个 .sample
文件,而 post-merge 则没有。 (git 版本 1.7.4)
提前致谢!
On one server I work on, we must log in as root (for reasons I won't get into here). We have a git repository set up which is used for the web server, but since files are created as root, files modified by git have the wrong permissions.
I created an incredibly simple post-merge hook which I thought would solve the problem.
#!/bin/bash
. git-sh-setup
chown -R www-data:www-data $GIT_DIR
I dropped this into .git/hooks/post-merge
with execute permissions, but the file never seems to run. This is the first time I've tried to set up a hook, so maybe I'm missing something obvious.
One thing I did notice is that most hooks had a .sample
file, while post-merge did not. (git version 1.7.4)
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能已经知道,但您可能想要检查合并后挂钩中的 EOL 字符 (CR)。这可能可以解释为什么你的钩子不执行(如另一个问题git-hook-post-merge-error-cannot-run
如果这不是解决方案,您也可以考虑另一种方法 。你的问题可以。当服务器上存储库中的文件发生更改时,创建一个任务来对目录执行所有者更改。 Cron 任务本身不会根据文件系统更改做出反应,但您可以尝试使用类似 inotify 对服务器的更改做出反应 。
我希望这两条信息能够解决您的问题,或者至少让您更接近
You might have already known but you might want to check for the EOL characters (CRs) in your post-merge hook. This might explain why your hook doesn't execute (as mentioned in this other question git-hook-post-merge-error-cannot-run.
If this isn't the solution you could also possibly look at another approach for your problem. You could make a task to perform the owner changes to your directory when a file in your repository change on the server. Cron tasks on their own do not react based on filesystem changes, but you could take a stab at using something like inotify to react to changes in the server's git repository on any changes.
I hope that these two pieces of information either solve your problem or at least puts you closer. Good luck.
确保将脚本添加到超级用户组所有权。
Ensure you add the script to the super user group ownership.
如果您希望脚本充当远程存储库,也许您正在寻找 post-receive hook被推到。
Perhaps you are looking for the post-receive hook, if you wish the script to act the remote repository is pushed to.
看看“git 成就”的工作方式。将 git 包装在脚本中并在任何命令中执行您需要的操作会更容易。挂钩更多地是为远程存储库而不是本地存储库设计的。合并是您在本地执行的操作,因此您不会从钩子机制中找到太多帮助。
链接:
http://benjamin-meyer.blogspot.com/2010/03 /git-achievements.html
希望这有帮助
Take a look at the way "git achievements" works. It would be easier to wrap git in a script and do what you need at any command. Hooks are designed more for the remote repo rather than local. Merge is something you do locally so you won't find much help from the hook mechanisms.
Link:
http://benjamin-meyer.blogspot.com/2010/03/git-achievements.html
Hope this helps