Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to preserve the file permission in git?

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?

like image 355
Richard Avatar asked Aug 23 '11 15:08

Richard


People also ask

How do you preserve permissions?

Preserve File Permissions Using cp You can use the -p option of cp to preserve the mode, ownership, and timestamps of the file. However, you will need to add the -r option to this command when dealing with directories. It will copy all sub-directories and individual files, keeping their original permissions intact.

What does Permission 644 and 755 mean for a file?

755 - owner can read/write/execute, group/others can read/execute. 644 - owner can read/write, group/others can read only.

What does chmod 644 mean?

Permissions of 644 mean that the owner of the file has read and write access, while the group members and other users on the system only have read access.


1 Answers

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.

like image 178
David Wolever Avatar answered Sep 30 '22 16:09

David Wolever