Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can/should I do about this git gc error? (rm: cannot unlink pack Permission denied)

When running git gc, I keep seeing this error:

rm: cannot unlink 'pack-30b1ff2[reset of hash].pack': Permission denied 

What can/should I do about this error?

Update

Sorry, I should have provided more info. Yes, I have tried a reboot. In fact,reboots have fixed gc issues for me before.

I only noticed this issue because when I open Git Gui, it prompts me now and then to compress the database. I eventually noticed that after a couple of times opening Git Gui that it kept prompting me, even though I clicked Yes, and it came back "successful".

So then I tried running it with Git EXT's Settings - Git maintenance - Compress git database command. This command told me that there was an error (red light in Git EXT whereas there was a green light in Git Gui).

The error I posted above however was from running git gc straight from git bash.

Should I schedule a disk scan? Could bad sectors be causing this? I was hoping this would be a quick answer :(

like image 330
danludwig Avatar asked May 05 '12 12:05

danludwig


People also ask

Why do I get permission denied in git bash?

The Bash permission denied error indicates you are trying to execute a file which you do not have permission to run. To fix this issue, use the chmod u+x command to give yourself permissions. If you cannot use this command, you may need to contact your system administrator to get access to a file.

When should you not run git gc?

See gc. auto below for how to disable this behavior. Running git gc manually should only be needed when adding objects to a repository without regularly running such porcelain commands, to do a one-off repository optimization, or e.g. to clean up a suboptimal mass-import.

What is gc command in git?

The git gc command is a repository maintenance command. The "gc" stands for garbage collection. Executing git gc is literally telling Git to clean up the mess it's made in the current repository. Garbage collection is a concept that originates from interpreted programming languages which do dynamic memory allocation.

What is git gc -- prune now?

git reflog expire --expire-unreachable=now --all removes all references of unreachable commits in reflog . git gc --prune=now removes the commits themselves. Attention: Only using git gc --prune=now will not work since those commits are still referenced in the reflog. Therefore, clearing the reflog is mandatory.


2 Answers

"Permission denied" on Windows is often caused by a lock from a running process. It's probable that there is a stalled Git EXT thread opened the pack file.

Try to do the git gc in safe mode.

Another option is to clone the repository in a new place and delete the old one.

like image 184
Dmitry Ovsyanko Avatar answered Oct 12 '22 01:10

Dmitry Ovsyanko


In my case it was TortoiseGit. To solve the problem I opened TortoiseGit Settings->Icon Overlays and set the Status cache to "None". Now the process TGitCache ended, so that all objects are "free" to be processed by git gc.

enter image description here

like image 21
schoetbi Avatar answered Oct 12 '22 00:10

schoetbi