git: Unable to index file - permission denied

h4xnoodle picture h4xnoodle · Jun 19, 2011 · Viewed 75.2k times · Source

Only for one file, I am getting the following error:

error: unable to write sha1 filename /opt/www/.git/objects/3f/ce3587c54a8be14c69b08c6b01f94949b11b47: Permission denied

error: wp/wp-admin/css/theme-install.dev.css: failed to insert into database
fatal: unable to index file wp/wp-admin/css/theme-install.dev.css

I checked my permissions on the file in question, the .git objects directory in question, and .git itself. I can add any other files except for this one. I could stat/r/w/touch the file, and touching did not help. The permissions are all correct.

Is this some crazy bug?

Answer

ShrapNull picture ShrapNull · Oct 8, 2015

If you are using visual studio or something similar that is generating the mdf file, simply close VS & retry your git command again. This time it should work.

To save constantly closing & reopening, you should add references into .gitignore file in the project root. For example, if it is a database causing the issue, add the following:

# SQL Server files
*.mdf
*.ldf