git – Cocoanetics https://www.cocoanetics.com Our DNA is written in Swift Mon, 08 Jul 2013 15:32:08 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.3 39982308 Zip Snapshot of GIT Repo https://www.cocoanetics.com/2013/07/zip-snapshot-of-git-repo/ https://www.cocoanetics.com/2013/07/zip-snapshot-of-git-repo/#comments Mon, 08 Jul 2013 15:30:30 +0000 http://www.cocoanetics.com/?p=8447 The sample apps I am making to accompany bug reports to Apple I generally create with a GIT repo behind them. I’ve gotten used to Xcode already creating a new repo when I start a new project, so why not make use of the GIT Goodness.

But when it then comes to attaching this project to a Radar I want the ZIP to be a small as possible. GIT provides several methods to achieve that.

If you have a GIT repo with several changes and possible some binary assets then you might have a folder which is much larger than essential.

23 MB for the Repo

Now Apple does not care about the history of how this sample came to be, they only care that it demonstrates the issue and for that you typically only want the latest version of all files. This example contains a JPEG image weighing in at 9 MB, but 23.2 MB is still more than twice the necessary size. Even funnier, if you try to zip the entire folder it also adds all the hidden git stuff producing a ZIP archive with a whopping 22.2 MB.

When I asked on Twitter, several people were quick to point me to some Stack Overflow Questions as well as yell the answer right back:

git archive

The command to produce a zipped snapshot of a specific branch is built into GIT, who knew!

Without the –output/-o parameter the archive is output to the terminal, which is not very useful. So we also want to specify the name of the file to output to.

The archive command supports several formats for archiving, shown from the –list/-l option.

  • tar
  • tgz
  • tar.gz
  • zip

Of course we want to use zip, we don’t feel like Unix geeks today who must tar.gz everything. If you don’t specify a format but specify the output file then git guesses the format from the file name. Without a file extension it falls back to tar.

So the minimum useful command is:

git archive HEAD -o demo.zip

Instead of HEAD you can also use other pointers to commits, like master or a commit SHA. Anything that allows git to know which commit to base the archive on. The result is much smaller than the 23 MB we started with:

More compact snapshot

11 MB is half the size and twice as bearable for upload over a slow ADSL connection. If you wanted to shave a couple more bytes off the archive you could specify the -9 option “compress better”. In this case it resulted in a reduction of a mere 2274 bytes. You might get better results if you don’t have a repo that’s almost entirely consisting of JPEG images.

Conclusion

Making use of Xcode’s auto-created git repos for new projects doesn’t mean you have to include all git history and meta data in the ZIP archive you attach to your bug reports. Yes, you can attach up to 100 MB of files to each Radar, but if you ever hit this limit you must be doing something wrong.

Apple wants small and sweet and to-the-point samples. The git archive command lets you produce a ZIP file that only contains a specific version of the repo. Very practical indeed.

]]>
https://www.cocoanetics.com/2013/07/zip-snapshot-of-git-repo/feed/ 4 8447