How to use git to commit read-only file?

7

1

I create a read-only file (file permission 444). When I use git add and git commit, I got a message as below:

[master (root-commit) 5b1336e] initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 a.txt

The file permission is changed to 644.

After I clone that repository, that file's permission is changed to 664.

How could I let git to keep original permission?

OS: Ubuntu 14.04 Git: 1.9.1

Enze Chi

Posted 2015-08-26T04:36:43.023

Reputation: 223

Answers

6

Git does not store file permissions except for the executable bit. I presume Git will simply use your current umask to set the access rights on any operations. And there's not much point in version controlling something you can't edit...

It looks like the core.fileMode configuration option controls this behaviour.

l0b0

Posted 2015-08-26T04:36:43.023

Reputation: 6 306

1I think it make sense in the scenario like the file is used as a global config file for a tool. In a project that use that tool, people have stupid script to modify it which will break other projects. And also you still can edit read only file manually and commit the it. So for git, it can track x why not do the same thing for r and w? – Enze Chi – 2015-08-26T06:54:48.077

1Git is not a deployment tool; you'll be much better off creating a package or installation script which gives files the correct rights on installation. This way you can also handle other file attributes such as for SELinux, and the deployed system won't contain a bunch of files which belong only on the developer desktop (.git directory, test files, etc.). – l0b0 – 2015-08-26T06:59:08.180