Git 在结帐时更改我的文件权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14557106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git changes my file permissions upon checkout
提问by Shiro
Our workflow is develop on a local machine, commit the changes to a central repository, then check out the branch of that repository that we need.
我们的工作流程是在本地机器上开发,将更改提交到中央存储库,然后检查我们需要的该存储库的分支。
The problem is that Git changes ownership and even file permissions of the files that it checks out, depending on the user making the checkout. A direct result of this is that our CSS files become unreadable after a checkout, as Git changes the file ownership to the person who did the Git pull in the webroot.
问题在于 Git 会更改其检出文件的所有权甚至文件权限,具体取决于进行检出的用户。这样做的直接结果是我们的 CSS 文件在结账后变得不可读,因为 Git 将文件所有权更改为在 webroot 中执行 Git 拉取的人。
Example:
例子:
- Before
git pull
:style.css
owned byuser_a:group_a
- After
git pull
:style.css
owned byuser_b:user_b
- 之前
git pull
:style.css
归user_a:group_a
- 之后
git pull
:style.css
归user_b:user_b
I want to keep ownership as user_a:group_a
. I don't want to have to log in every time one of my team has made a change to the files, and change the ownership back to the original configuration.
我想将所有权保留为user_a:group_a
. 我不想每次我的团队对文件进行更改时都必须登录,并将所有权更改回原始配置。
How do other people deal with this? How do you deal with repositories used by multiple users. We have suphp on our system and cannot take it off.
其他人如何处理这个问题?您如何处理多个用户使用的存储库。我们的系统上有 suphp 并且无法将其关闭。
回答by eis
Git does not change file permissions or ownership. It's just that it (mostly) doesn't store it either, it doesn't exist in your repo, so they get changed to whatever your user has. Just like with any file creation.
Git 不会更改文件权限或所有权。只是它(大部分)也不存储它,它不存在于您的存储库中,因此它们会更改为您的用户拥有的任何内容。就像任何文件创建一样。
Git supports two permission sets: executable bit on and executable bit off. Nothing else. Ownership information is not stored at all.
Git 支持两种权限集:可执行位开启和可执行位关闭。没有其他的。根本不存储所有权信息。
See this thread- "If you want specific permissions, you'll need to do it manually."
请参阅此线程- “如果您需要特定权限,则需要手动执行。”
There are some solutions suggested: you can use a separate tool to do it for you, use a proper combination of user account and umask to set them properly by default or write a git hook yourself to do it. A hook would've to be installed on the user doing the checkout.
有一些建议的解决方案:您可以使用单独的工具为您完成,使用用户帐户和umask的适当组合在默认情况下正确设置它们或自己编写一个git hook来完成。必须在结账的用户身上安装一个钩子。
Like @ikke said in the comments, Git is not really a deployment tool and should not be used as such. It is a version control system for source code.
就像@ikke 在评论中所说的那样,Git 并不是真正的部署工具,不应如此使用。它是源代码的版本控制系统。
回答by tishma
For me, the best solution was creation of a shell script that fixes the permissions. For example:
对我来说,最好的解决方案是创建一个修复权限的 shell 脚本。例如:
.git/hooks/post-checkout:
#!/bin/sh
chmod +x tools/*
Btw, checkout is not the only case when git does mess with permissions, it's also when you pull. I handle that with .git/hooks/post-merge
hook.
顺便说一句,结帐不是 git 弄乱权限的唯一情况,当您拉取时也是如此。我用.git/hooks/post-merge
钩子处理。
Ideally, you can create a shell script that fixes permissions somewhere in your repo (e.g. tools/fixpermissions.sh
), and call it in both hooks. Don't forget to change the permissions for that file manually ;)
理想情况下,您可以创建一个 shell 脚本来修复存储库中某处的权限(例如tools/fixpermissions.sh
),并在两个钩子中调用它。不要忘记手动更改该文件的权限;)
#!/bin/sh
chmod a+x tools/fixpermissions.sh
tools/fixpermissions.sh
回答by Chronial
The easiest solution is to just run git as user_a
.
最简单的解决方案是运行 git as user_a
。
回答by Calpau
I often run a
我经常运行一个
git checkout -f file.xml
... on a versioned file.xmlwith world-write permissions, as I continually modify it and want to return it to the normal state.
...在具有世界写入权限的版本化file.xml上,因为我不断修改它并希望将其恢复到正常状态。
But that resets the permissions. A slightly longer version:
但这会重置权限。稍微长一点的版本:
git show HEAD:./file.xml > ./file.xml
Just resets the content.
只是重置内容。
回答by andrepo
Alternatively you can set a default permission for the folder in question like so: https://unix.stackexchange.com/questions/1314/how-to-set-default-file-permissions-for-all-folders-files-in-a-directory
或者,您可以为相关文件夹设置默认权限,如下所示:https: //unix.stackexchange.com/questions/1314/how-to-set-default-file-permissions-for-all-folders-files-in -a-目录