简体   繁体   English

使用 git 合并后修复权限

[英]Fix permissions with git post-merge

On one server I work on, we must log in as root (for reasons I won't get into here).在我工作的一台服务器上,我们必须以 root 身份登录(原因我不会进入这里)。 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.我们设置了一个 git 存储库,用于 web 服务器,但由于文件是作为 root 创建的,因此由 git 修改的文件具有错误的权限。

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.我将它放入具有执行权限.git/hooks/post-merge中,但该文件似乎永远不会运行。 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.我确实注意到的一件事是大多数钩子都有一个.sample文件,而 post-merge 没有。 (git version 1.7.4) (git 版本 1.7.4)

Thanks in advance!提前致谢!

You might have already known but you might want to check for the EOL characters (CRs) in your post-merge hook.您可能已经知道,但您可能想检查合并后挂钩中的 EOL 字符 (CR)。 This might explain why your hook doesn't execute (as mentioned in this other question git-hook-post-merge-error-cannot-run .这可能解释了为什么你的钩子没有执行(正如另一个问题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. Cron 任务本身不会根据文件系统更改做出反应,但您可以尝试使用类似inotify的东西来对服务器 git 存储库中的任何更改做出反应。

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.确保将脚本添加到超级用户组所有权。

Perhaps you are looking for the post-receive hook , if you wish the script to act the remote repository is pushed to.也许您正在寻找post-receive 钩子,如果您希望执行远程存储库的脚本被推送到。

Take a look at the way "git achievements" works.看看“git 成就”的工作方式。 It would be easier to wrap git in a script and do what you need at any command.将 git 包装在脚本中并在任何命令中执行您需要的操作会更容易。 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 http://benjamin-meyer.blogspot.com/2010/03/git-achievements.html

Hope this helps希望这可以帮助

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

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