Search code examples
gitgit-push

git: Is it possible to save the packed objects of a dry run and push them later?


I'm trying to push a bunch of commits that contain a lot of code and a few thousand MP3 and PDF files besides (ranging from 5-40 MB each).

Git successfully packs the objects:

C:\MyProject> git push
Counting objects: 7582, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7510/7510), done.

But it fails to send the push for some as yet unknown reason.

The problem is that it takes it a very long time to repack the files (I'm on a battery-powered laptop and it took about 20 minutes to pack).

So I guess my question can be phrases thus:

  1. Is it possible to save the packed objects created in a dry run?
  2. Once saved, is it possible to push those packed objects and avoid repacking?

I looked it up in the git manual and elsewhere and couldn't find anything conclusive.

Any help or pointers are appreciated.


EDIT - Added the error messages:

The first time I ran this from the commandline (`git push') I got this error:

fatal: sha1 file '<stdout>' write error: Invalid argument
error: pack-objects died with strange error
error: failed to push some refs to 'account@server:project.git'

The second time (git push origin master -v) I got this error:

Pushing to account@server:project.git
Counting objects: 7582, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7510/7510), done.
fatal: sha1 file '<stdout>' write error: Invalid argument
error: pack-objects died with strange error
error: failed to push some refs to 'account@server:project.git'

Note that in both cases, after the compression finished, I got this dialog:

---------------------------
PuTTY Fatal Error
---------------------------
Network error: Software caused connection abort
---------------------------
OK   
---------------------------

While the dialog was open, the console read as follows (the "Writing objects" line was erased after clicking OK):

Pushing to account@server:project.git
Counting objects: 7582, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (7510/7510), done.
Writing objects:   0% (1/7525)

EDIT 2 - After running git gc per Charles Bailey's suggestion, I got the following output after about 1.5 hours:

C:\Projects\MyProject>git gc
Counting objects: 10926, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (10125/10125), done.
warning: failed utime() on c:/Projects/MyProject/.git/objects/.tmp-10596-pack-a3a5ef775308593167a669b19aa752d2f484f768.pack: Permission denied
warning: failed utime() on c:/Projects/MyProject/.git/objects/.tmp-10596-pack-380270a0b5f3c7d30731c8e19f9271a59ea05e3d.pack: Permission denied
Writing objects: 100% (10926/10926), done.
Total 10926 (delta 719), reused 10858 (delta 719)
mv: cannot move `/c/Projects/MyProject/.git/objects/pack/pack-5dc233ff7aa1c33fc4845251186d5bafcefe3a11.pack' to `/c/Projects/MyProject/.git/objects/pack/old-pack-5dc233ff7aa1c33fc4845251186d5bafcefe3a11.pack'
error: failed to run repack

Solution

  • If you run git gc then git will pack all reachable objects in your repository. When you subsequently push, it will appear to repack the objects that it needs to push to the remote repository but it will be able to re-use the packed for that are in your local pack file and it should run a lot faster.