Git Checkout warning: unable to unlink files, permission denied
I am aware that there are similar issues about git relating to the 'unable to unlink' warn开发者_StackOverflowing, but I have not been able to use them.
The main difference is that this happened when I have not been dealing with submodules in any way (I have never dealt with them before). I created a branch called 'upgrade', deleted my old framework files, and copied in the new ones. I used git add -A, then committed everything. When I tried to checkout the trunk branch, it responded with the following errors:
warning: unable to unlink requirements/views/sk/index.php: Permission denied
warning: unable to unlink requirements/views/sv/index.php: Permission denied
warning: unable to unlink requirements/views/zh/index.php: Permission denied
warning: unable to unlink requirements/views/zh_cn/index.php: Permission denied
warning: unable to unlink requirements/views/zh_tw/index.php: Permission denied
...etc. There are hundreds of them.
At first I thought this was simply a permissions problem, and so I added group write permissions to the entire requirements directory recursively, but there was no change.
Edit: As suggested in an answer below, I attempted to do the same thing but with everything else closed. I had no more luck than before.
This issue is particularly debilitating as I cannot move to trunk to get back to normal development.
In my first encounter with this error my user had rights to "write" to the file but not the containing directory. Check the permissions of the directory containing the file.
I usually see that kind of error when there is a process not releasing the handle of those files.
Make sure nothing is running, and then try your checkout again.
Note: it can also be related with the way Git has been installed (on Windows, UAC can generate problem if msysgit is installed in C:\Program
or C:\Program Files
, see "msysgit - sh.exe - fork: Permission denied - Vista 64 bit" and comment 2 of issue 437)
Note: as illustrated below, a common other cause of the problem is rights issue on the directory (wrong owner), not necessarily on the file that can't be unlinked.
"Unlink" essentially means "delete file" in this case.
This error is not caused by git itself. You should have similar errors deleting those files manually, in a command line or file explorer.
You don't have the access permission, maybe because you are not the owner.
Fix by changing the owner to yourself:
sudo chown -R your_login_name /path/to/folder
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.
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.
This can also occur when:
You ran a process inside a Docker container, and:
Some files were generated by that process, and:
The destination of the files is mounted as a volume on the Docker host, and:
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.
I ran into this problem whenever running "git repack" or "git gc" on my OS X machines, even when running git with admin privileges, and I finally solved it after coming across this page: http://hints.macworld.com/comment.php?mode=view&cid=1734
The fix is to open a terminal, go to your git repo, cd into the .git folder, and then do:
chflags -R nouchg *
If that was the issue, then after that, your git commands will work as normal.
To those who are using Intellij, as @rtconner said this problem is not caused by git. Since your IDE is locked a file(s) git cannot un-link it. So, you need to close your IDE and then try to merge (or whatever you like) it via command line.
on terminal on mac i just do this
sudo git checkout . ( to clean up everything )
and then
sudo git pull origin
In my case it was a ":" character in a folder name prevenitng the git repo to checkout on windows.
I had this error inside a virtual machine (running Ubuntu), when I tried to do git reset --hard
.
The fix was simply to run git reset --hard
from the OS X host machine instead.
In my case, my Windows directory is under the Dropbox folder. It is not a Git-specific issue. When a file (in this case, the lock file) has just been created, it takes Dropbox another second to do the synchronization. During that time, the file is in use by Dropbox, and any 3rd party program (in this case, Git) cannot delete the file.
My solution is to quit Dropbox and therefore avoiding the behind-the-scenes magic of Dropbox's file synch.
None of the other suggestions worked for me, but this did:
sudo git reflog expire --expire=now --all && sudo git gc --prune=now --aggressive
I have encountered this error and it is caused by wrong "owner/group" of the file/folder. You must seek assistance to your server admin to change the "owner/group" of this file/folder and retry using "git pull" again. Or if you are a sudoer, just sudo chown "your owner name / your group name" and try again pulling your repository. Try it, it works 100% to me!
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.
Just in general, if this happens in Windows, and you are using tortoisegit, it is the status cache of tortoisegit. Kill that process and it will be freed.
I just had to switch user from ubuntu to my actual user name that I'd first done stuff under. That fixed it.
Solved for me by setting my git client (GitExtensions) to always run in admin mode.
I had that problem while using IntelliJ
(14.1.3 Ultimate), I wanted to revert changes in some file.
Solved by closing Git Bash
opened in another window - another revert trial in IntelliJ
worked.
I encountered this error and I think the issue was that I had 'run as admin' when I started Eclipse and created the files, therefore they were owned by Admin (noticed by running 'ls -la' on the folder). When I later tried to stash the files, it didn't let me ('unable to unlink files' and all that). Doing a chmod on the files was the fix for me.
git gc worked for me (in a new tab). Was getting this with every rebase. Thanks http://www.saintsatplay.com/blog/2016/02/dealing-with-git-unlink-file-errors#.W4WWNZMzZZJ
All you need to do is provide permissions, run the command below from the root of your project:
chmod ug+w <directory path>
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
In my case the permission problem solved by setting www-data
as an owner:
chown -R www-data project_folder_name
I've encountered this error while running Git Bash on a windows box. In my particular case I just needed to open Git Bash as administrator.
For me, at the top of the message there was:
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
error: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log.
Automatic cleanup will not be performed until the file is removed.
So I removed the file with rm .git/gc.log
, and then I got:
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
error: The last gc run reported the following. Please correct the root cause
and remove .git/gc.log.
Automatic cleanup will not be performed until the file is removed.
warning: There are too many unreachable loose objects; run 'git prune' to remove them.
After running git prune
, everything was back to normal.
I solved this problem, just by delete all temp data > Run>%temp% >Hit enter and delete all temp files and restarting the computer. For me it is working now.
I had the same problem on Windows. Fixed it by using the following command instead:
git show feature-branch:./filePath > ./filePath
精彩评论