0

I've followed the guides and managed to create a zip archive of my git repository, by doing this:

git archive HEAD --format=zip > c:\myarchive.zip

The reason I want to do this is that I'm done with the project, so I'm going to delete the VM I've been doing development on, but I want a backup of the work I've done so that I can refer to it later if I need to. However, I can't figure out how to open the zip file that is created.

Normally, I would double-click on a zip file to open it, but when I do, I see this error:

Windows cannot open the folder.
The Compressed (zipped) Folder 'C:\myarchive.zip' is invalid.'

I've tried recreating the zip file a couple of times, but it didn't change anything. Any thoughts?

CodeThug
  • 3,054
  • 1
  • 21
  • 17

4 Answers4

9

WARNING git archive does not create an archive of yor git repository; it creates an archive file that contains a snapshot of the contents of the given commit.

To create a true archive (if you cannot reasonably just push to a safe repository) you should use git bundle and make sure to include all your branches.

CB Bailey
  • 755,051
  • 104
  • 632
  • 656
1

unzip to a directory.

The git archive command seems to be one way and help you create a zip archive, but assumes use of a zip tool to unzip.

Toby Allen
  • 10,997
  • 11
  • 73
  • 124
  • "Unzip to a directory" <--- this; Not sure what the `cd dir; git checkout` bit would accomplish - pretty sure it's nothing, since the archive only contains a copy of the working directory, not the repository... – twalberg Jun 29 '12 at 15:49
  • use 7-zip,pkzip,winzip etc to unzip then! – Toby Allen Jun 29 '12 at 16:54
  • I tried double-clicking on it, and I got an error that "The Compressed (zipped) Folder 'C:\myarchive.zip' is invalid." Any other thoughts? Did this work for you? – CodeThug Jun 29 '12 at 19:20
  • I just did it and had no problem unzipping. Download 7-Zip and try that, you must have a corrupt zip file – Toby Allen Jun 29 '12 at 20:43
  • I also tried 7-zip and got the same error. Strange... Oh well... this seems to be a reasonable answer - I must just have something wrong with my system. – CodeThug Jun 30 '12 at 13:05
0

Not quite sure why you want to do this (apart from seeing if you can). If you are strugging with Git (it is a bit of a learning curve) there are some videos which we made when we were going through the same process. We recorded the guy who helped us... http://www.ava.co.uk/git Hope they help

Ian P
  • 1,724
  • 1
  • 10
  • 12
  • What's the point of an archive if you can pull anything out of it? I want to create an archive, then I later want to pull data out of it. – CodeThug Jun 29 '12 at 19:10
  • The idea of GIT is (distributed) version control: You start writing an app (script) or document (script). You save (commit) a version of that script to the local repository (often referred to a repo). You "Push" the local repository to a server to create an (off site?) backup. Another member of the team (or you) can "Pull" your changes to another pc. You can both work off line. You can branch you code so multiple features can be worked on simutaneously and independantly. These can be then merged back together to produce a composite. At all points you have a restorable version of all saves. – Ian P Jun 30 '12 at 16:10
  • Yes, I know how Git works, and we have that exact setup which has been working great for several months. However, now we are shuttering the project, we won't be paying for BitBucket any more, and I need to get rid of the VM that I've been doing development on - but I want to save a copy of the code. So the repositories, both local and remote - will soon be gone. Thus, the need for an archive. – CodeThug Jul 03 '12 at 13:10
  • Ah OK, Well reading the other comments, if your zip file contents is greater than the windows limit, you need to use winzip or 7zip. If it is greater then you will get an invalid response from Windows or an invalid wzip - not many people know windows has this limit. http://support.microsoft.com/kb/301325 so after all that I'g just zip up the repository and scatter over numerous DVDs or in a cloud. – Ian P Jul 03 '12 at 16:27
0

I had the same issue when trying to archive a git repo using powershell. Trying it with cmd, it worked like a charm.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Smino_
  • 15
  • 4