git: Unable to index file - permission denied

后端 未结 7 878
粉色の甜心
粉色の甜心 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:01

    I was having this problem on my bare origin repository when the permissions were root:git 770, apparently I had to change it to 771, even though my user is in the git group. I suspect perhaps git is perhaps either not acl-aware, or not so compatible with secondary groups, as the git group was one of my secondary groups in this case.

    0 讨论(0)
  • 2020-12-29 03:07

    Just close the Visual Studio (or Unity) and try to add those files again.

    0 讨论(0)
  • 2020-12-29 03:11

    Something has gone awry in your git repository likely caused by an external process creating a file or directory which is owned by a user other than the current user.

    This error is common when using Docker, and a service in your docker-compose.yml file has a locally mounted volume which was created using a different user to that of the local machine user.

    If this is the first time that this error has occurred, execute the below on your working directory to change the ownership of files and folders back to the logged in user:

    sudo chown -R ${USER}:${USER} .
    

    If this is not the first time you have encountered this issue, i.e. you have already committed and pushed files and folders that are owned by another user, then the above alone will not rectify the situation, as well as executing the above command - you will need to carry out the following instructions.

    By far, the quickest fix is to execute the following from your root project directory which holds your git repository:

    sudo chown -R ${USER}:${USER} .git/objects
    

    To test that everything is fixed, execute the following:

    git add .
    

    Quickly followed by executing:

    git status
    

    You will see that everything has been added to the git repository without any need to test / fiddle around with anything any further.

    0 讨论(0)
  • 2020-12-29 03:12

    You don't have permission to write in /opt/www/.git/objects/3f.

    The quickest solution is to use the sudo command to execute your command with root privileges.

    sudo <Your git command>

    Solved it for me.

    0 讨论(0)
  • 2020-12-29 03:12
    error: open("3/BasicMVVM/.vs/BasicMVVM/v16/Server/sqlite3/db.lock"): Permission denied
    

    error: unable to index file 3/BasicMVVM/.vs/BasicMVVM/v16/Server/sqlite3/db.lock fatal: adding files failed

    if you have such error and you are working on visual studio.first you close the visual studio. git bash and write "git add * " with out inverted commas and on the suitable place it will work for my self

    0 讨论(0)
  • 2020-12-29 03:19

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