Git Checkout warning: unable to unlink files, permission denied

后端 未结 26 1101
梦毁少年i
梦毁少年i 2020-12-04 08:46

I am aware that there are similar issues about git relating to the \'unable to unlink\' warning, but I have not been able to use them.

The main difference is that th

相关标签:
26条回答
  • 2020-12-04 09:20

    I think it's about your file permission:

    sudo chmod 777 -R <your-git-folder>
    
    0 讨论(0)
  • 2020-12-04 09:22

    I had the same issue , I tried few alternatives as others suggested.

    But finally giving correct permission to .git folder solve the issues.

    sudo chown -R "${USER:-$(id -un)}" .git
    
    0 讨论(0)
  • 2020-12-04 09:24

    This can also occur when:

    1. You ran a process inside a Docker container, and:

    2. Some files were generated by that process, and:

    3. The destination of the files is mounted as a volume on the Docker host, and:

    4. You are running git on the Docker host.


    If this is the case, stage the files you wish to commit and run:

    git diff --name-only --cached | xargs ls -l 
    

    Files which meet the above criteria will be prefixed with:

    -rw-r--r-- 1 root root ...
    

    They are owned by root and not writable, which is not good. To fix that run:

     git diff --name-only --cached | xargs -i sh -c 'sudo chown $USER:$USER {}; chmod +w {}'
    

    A cleaner solution would probably be to use the --user option, see this for Docker and this for Docker compose.

    0 讨论(0)
  • 2020-12-04 09:26

    You can change the write permissions to get it done.

    sudo chmod -R ug+w . 
    

    This command will give 'w' permissions to all the folders in the current directory.

    0 讨论(0)
  • 2020-12-04 09:26

    Make sure that any associated processes or threads are not running and perform end task or force quit as necessary.

    Make sure you change the ownership permission.

    0 讨论(0)
  • 2020-12-04 09:28

    I was having the issue with a default-settings.php file in drupal 7. In this case I wasn't able to delete it or revert it just like @rtconner said. I didn't have an application or anything using this file, and it ended up being a permissions error.

    I added chmod 777 * to the folder and then I was able to revert it no problem.

    0 讨论(0)
提交回复
热议问题