Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git: Unable to index file - permission denied

Tags:

git

indexing

add

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?

like image 569
h4xnoodle Avatar asked Jun 19 '11 05:06

h4xnoodle


People also ask

What is git inde?

Git Index may be defined as the staging area between the workspace and the repository. The major use of Git Index is to set up and combine all changes together before you commit them to your local repository.

What git add does?

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way—changes are not actually recorded until you run git commit .


2 Answers

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 
like image 162
ShrapNull Avatar answered Sep 29 '22 10:09

ShrapNull


Looking at the Git source code (sha1_file.c, function move_temp_to_file()) it looks like Git is failing to rename a temporary file named /opt/www/.git/objects/3f/tmp_obj_XXXXXX (where XXXXXX is six random characters) to /opt/www/.git/objects/3f/ce3587c54a8be14c69b08c6b01f94949b11b47. This can happen if you don't have permission to delete files in /opt/www/.git/objects/3f.

Some things to try:

  • If multiple users accessing the Git repository, you may need to run something like git config core.sharedRepository 0664 (see git help config for details) to ensure that newly created directories and files have proper permissions for all users of the repository.
  • Try running rm -f /opt/www/.git/objects/3f/tmp_obj_* and see if that makes the problem go away.
  • See if you can reproduce the problem outside of Git by doing the following:

    mkdir -p /opt/www/.git/objects/3f cd /opt/www/.git/objects/3f rm -f tmp_obj_* ce3587c54a8be14c69b08c6b01f94949b11b47 echo "testing" >tmp_obj_abcdefg mv tmp_obj_abcdef ce3587c54a8be14c69b08c6b01f94949b11b47 rm -f tmp_obj_abcdefg 

    Be sure to run the above commands the same user that experienced the error.

  • Try recursively chowning and chmoding the objects directory.
like image 23
Richard Hansen Avatar answered Sep 29 '22 09:09

Richard Hansen