git 如何在git中保留文件权限?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7163736/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 05:53:22  来源:igfitidea点击:

How to preserve the file permission in git?

databasedjangogitpermissions

提问by Richard

I encountered a problem which took me a long time to find a solution and still fail to get one.

我遇到了一个问题,我花了很长时间才找到解决方案,但仍然没有得到解决。

The problem I had is 'DatabaseError: 'attempt to write a readonly database' when I tried to deploy my website through git to a Django hosting.

当我尝试通过 git 将我的网站部署到 Django 托管时,我遇到的问题是“DatabaseError: 'attempt to write a readonly database'”。

It seems like git will change the permission of my files, from 777 to 755. But whenever I commit my project, this change will persist. However, I still need to write something into my database (sqlite database).

似乎 git 会更改我的文件的权限,从 777 到 755。但是每当我提交我的项目时,这种更改都会持续存在。但是,我仍然需要向我的数据库(sqlite 数据库)中写入一些内容。

Does anyone have a suggestion to configure my git to preserve the permission mode at each commit?

有没有人建议配置我的 git 以在每次提交时保留权限模式?

回答by David Wolever

In short, you can't.

简而言之,你不能。

In longer, there are projects like etckeeper which can do it automatically, or you can write a small hook script which will fix up the permissions (which is probably how I'd do it).

在更长的时间里,有像 etckeeper 这样的项目可以自动完成,或者您可以编写一个小的钩子脚本来修复权限(这可能是我的方式)。

For example, if you commit something this:

例如,如果您提交以下内容:

#!/bin/sh
chmod -R XXX file_or_directory/

To, eg, scripts/fix_permissions/, then run it as a post-receivehook by simlinking it into .git/hooks/post-receiveon the server.

例如,通过将它连接到服务器上scripts/fix_permissions/,然后将它作为接收后挂钩运行.git/hooks/post-receive