Git Checkout warning: unable to unlink files, permission denied

后端 未结 26 1217
梦毁少年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条回答
  •  猫巷女王i
    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.

提交回复
热议问题