Apr 08 2017

git unpack failed: error Missing tree solution

Category: English posts,TechnicalIuliana @ 19:18

More than a year ago, I convinced the company that I work for to switch from CVS to Git. This was not done as I wanted it, because … management… and thus a lot of stupid issues appeared. I did Git support for more than a year, and all this time 80% was Eclipse support, because the EGit Eclipse plugin is … a mess.  Now after more than a year later, a new problem appeared. When people tried to push their changes, a nasty pop-up appears:

And after you get this pop-up, doing it from the command line, doesn’t do it either:

C:\work>git push -v
Pushing to ssh://gigi.pedala@git:29418/gmp-parent
Counting objects: 91, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (85/85), done.
Writing objects: 100% (91/91), 44.68 KiB | 0 bytes/s, done.
Total 91 (delta 41), reused 0 (delta 0)
remote: Resolving deltas: 100% (41/41)
fatal: Cannot receive pack: error: unpack failed: error Missing tree 07b3431321048e15dccc9e022e258b93252894ef
To ssh://gigi.pedala@git:29418/gmp-parent
! [remote rejected] HEAD -> hotfix/H5.14.0.XX_ADV_XMW_branch (n/a (unpacker error))
error: failed to push some refs to ‘ssh://gigi.pedala@git:29418/gmp-parent’

If you search for a solution on the internet for this, you will most probably be told that your repository is corrupted and that the only solution is to re-clone it. Or you will be required to execute a lot of commands… that might do nothing for you.

Two days ago a colleague of mine from Frankfurt had it. As I was in the office I took the other Git expert in the company with me and went to his computer to dissect his repo. And being the nice person that I am, I will share the solution with you. We ran a git gc

git gc
Runs a number of housekeeping tasks within the current repository, such as compressing file revisions (to reduce disk space and increase performance) and removing unreachable objects which may have been created from prior invocations of git add.

Basically, when you do a push, git packages the information and tries to send it to the remote. Problem is that, whatever is sent to the remote in this case, cannot be unpacked because a git tree is missing for some reason. If you try to do a git show on the tree with the SHA1 code mentioned in the error, all the information is there. So what is happening? Well, git gc will help you here, because when trying to repack the information, you will get a set of errors like these:

cannot unlink file .git/objects/pack…”

Apparently Eclipse, or any other program, or even Windows holds a lock on the repository files, which prevents packing, and obviously incomplete information is send to the remote which cannot unpack it, thus the upacker error problem. I mentioned Windows here, because I haven’t heard anybody having this problem on a Unix system yet.

The solution for my colleague was to restart his computer(we closed Eclipse, but some java processes were still hanging and keeping the files locked so we took the easy way out) and before opening any other program execute git gc. The operation executed without any errors and he was able to continue his work, and do any remote operations he needed.

So this is the easiest solution: restart the computer, do a git gc and go about your work as usual.

Tags: , ,