git: Unable to index file - permission denied

后端 未结 7 879
粉色の甜心
粉色の甜心 2020-12-29 02:34

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

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


        
相关标签:
7条回答
  • 2020-12-29 03:20

    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.
    0 讨论(0)
提交回复
热议问题