Thursday 19 November 2015

How to fix "Unlink of file '.git/objects/pack/pack-(longhash)' failed. Should I try again? (y/n)

possible tags: Git GC, git cleanup repository, 

Every now and then while using Git, like say when you do a "git pull" on a repository which regularly gets a lot of changes, you will get a message from Git like this:

Auto packing the repository for optimum performance. You may also
run "git gc" manually. See "git help gc" for more information.
Counting objects: 499419, done.
Delta compression using up to 24 threads.
Compressing objects: 100% (164548/164548), done.
Writing objects: 100% (499419/499419), done.
Total 499419 (delta 238160), reused 493660 (delta 233258)

And then you might see this:

Unlink of file '.git/objects/pack/pack-061698b76ddcbea46c9d31874b73c9a66d87f790.pack' failed. Should I try again? (y/n)
n
Unlink of file '.git/objects/pack/pack-061698b76ddcbea46c9d31874b73c9a66d87f790.idx' failed. Should I try again? (y/n)

You'll find that if you press "n", you'll find yourself pressing "n" a *lot* of times... this is pretty much the point where you should just go:

Ctrl-C 

and then just do a 

$ git gc

to manually pack your repository.

$ git gc
Counting objects: 499419, done.
Delta compression using up to 24 threads.
Compressing objects: 100% (159646/159646), done.
Writing objects: 100% (499419/499419), done.
Total 499419 (delta 238160), reused 499419 (delta 238160)
Removing duplicate objects: 100% (256/256), done.
Checking connectivity: 499419, done.


Done!