How do I export the revision history of a gdoc to git?

ecmanaut picture ecmanaut · Jan 8, 2013 · Viewed 13k times · Source

I have a spreadsheet in google docs that I'd want to integrate in a git workflow (and push to github). Are there any tools (or even libraries that are gdoc version aware) that do, or help me do, that?

I have some old ruby hacks lying around based on the google_spreadsheet gem that reads and writes current versions of a csv gdoc, but nothing which extracts revision history.

Answer

larsks picture larsks · Jan 9, 2013

I was intrigued by your question, so I hacked together a little project today:

Given a document id, it will create a git repository using either the plain text or HTML content of a Google Docs document. This could easily be extended to work with other file types. It looks something like this when it works:

$ python gitdriver.py -T 1j6Ygv0ow5A8_ywTMwJbuKVrxrSsSH2wJs3a8Q66mvt4
Create repository "Untitled"
Initialized empty Git repository in /home/lars/projects/gitdriver/Untitled/.git/
[master (root-commit) 24d35e7] revision from 2013-01-08T21:57:38.837Z
 1 file changed, 1 insertion(+)
 create mode 100644 content
[master fd243ee] revision from 2013-01-08T21:57:45.800Z
 1 file changed, 1 insertion(+), 1 deletion(-)
 rewrite content (95%)
[master 5ad1a26] revision from 2013-01-09T01:47:29.593Z
 1 file changed, 1 insertion(+), 1 deletion(-)
 rewrite content (92%)
$ cd Untitled
$ git log --oneline
5ad1a26 revision from 2013-01-09T01:47:29.593Z
fd243ee revision from 2013-01-08T21:57:45.800Z
24d35e7 revision from 2013-01-08T21:57:38.837Z

This requires you to set up the necessary application credentials with Google. And it doesn't do any error checking. And may eat your goldfish. This is meant as a demonstration of the API and how you might do something like this; it's not intended to be a functional product.