How to preserve the file permission in git?
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).
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-receive hook by simlinking it into .git/hooks/post-receive
on the server.
Related videos on Youtube
Richard
I am interested in systematic analysis of languages and NLP application development, especially for language learning, market analysis and consulting.
Updated on June 08, 2022Comments
-
Richard almost 2 years
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.
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).
Does anyone have a suggestion to configure my git to preserve the permission mode at each commit?
-
Amber over 12 yearsNote that if you should probably using a post-receive hook to update the files your server is running from anyway, since running something directly out of a Git repository on a server is typically a Bad Idea.
-
David Wolever over 12 yearsThat is very true. I like to keep my hooks in the repo, so they are versioned along with everything else, but that's because I work on small projects where all the developers have root access to the servers anyway… But it certainly does open up a potential security hole.