更新文件时,Git更改默认的umask [英] Git change default umask when update file
问题描述
我有一个Git问题。我在Google和StackOverflow中搜索了一个解决方案,但没有任何帮助。
问题是,每次git更新工作目录中的某个文件(当我检出分支或I合并分支等),则文件权限被改变,以便添加可写入组标志。
我的apache显示文件Error 500,如果它可写入组中。
示例:
我有一个文件index.php 。权限是-rwxr-xr-x。当前(活动)分支是主。该文件在开发分支中进行了更改。
我执行git checkout develop,文件index.php获得权限-rwxrwxr-x(可写入组添加)。我的网站停止工作。由于apache不允许在php文件中使用这个标志(我不知道为什么,但是我不能改变它)。
每次执行git checkout develop 我还需要执行chmod gw index.php。我不喜欢执行两个命令(有时我忘记执行这个操作,而我的网站也无法运行)。
我能做些什么来解决这个问题?
我认为这与umask有关。我做了一些在网络上找到的技巧,但没有任何效果。
谢谢。
允许将文件作为二进制文件执行是危险的。
无论如何,我用umask解决了这个问题。我的 post-receive
脚本看起来像:
!/ bin / sh
umask 002
GIT_WORK_TREE = / var / www / site git checkout -f
因此,文件权限
s设置为 664
和目录权限
设置为 775
,这非常适合我。
PS在 .profile
文件中设置umask git
用户不起作用,我不明白为什么,请评论如果你知道为什么会发生这种情况,那就出来了。
I have a problem with Git. I searched for a solution in Google and in StackOverflow but nothing helps.
The problem is that every time git updates some file in the working directory (when I checkout branches or I merge a branch, etc.) then the file permissions are changed such that the "writable to group" flag is added. And my apache shows "Error 500" for the file if it is writable to group.
Example: I have a file index.php. Permissions are "-rwxr-xr-x". Current (active) branch is master. This file was changed in the branch "develop". I execute "git checkout develop" and the file index.php gets permissions "-rwxrwxr-x" (writable to group is added). And my site stops working. As apache doesn't allow this flag in php files (I don't know why but I can not change this).
Every time when I execute "git checkout develop" I need to execute also "chmod g-w index.php". I don't like to execute two commands (and sometimes I forget to execute this and my site doesn't work).
What can I do to solve this problem? I think this is something related to umask. I did some tricks I found on web, but nothing works.
Thanks.
It is kind of dangerous to allow file execution as a binary.
Anyway I solved the problem with umask. My post-receive
script looks like:
!/bin/sh
umask 002
GIT_WORK_TREE=/var/www/site git checkout -f
So, file permission
s set to 664
and directory permissions
set to 775
, which suits me perfectly.
P.S. Setting umask in a .profile
file of git
user has no effect, and I don't understand why, please comment out if you know why this happens.
这篇关于更新文件时,Git更改默认的umask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!