24

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.

ecmanaut
  • 5,030
  • 2
  • 44
  • 66
  • See some 2018-19 work-in-progress on this via R at https://github.com/tidyverse/googledrive/issues/219 – nealmcb Jul 17 '19 at 14:58

2 Answers2

34

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.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • This seems a cool start – what python version and dependencies do I need to install to run it? I tried running it with python 2.7 after having run pip install `google-api-python-client`, `pyyaml` and `requests` but still got some backtrace: https://gist.github.com/4514298 – ecmanaut Jan 11 '13 at 22:00
  • 1
    There's something very odd about that traceback; it's reporting that your `os` module has no `urandom` function. How did you install Python 2.7? For the record, this works fine under both OS X and Linux (w/ Python 2.7 and requests 1.1.0). – larsks Jan 12 '13 at 02:37
  • 1
    This is fantastic larsks, thanks for writing it up and posting it. I did have some trouble with truncated revisions lists and such that seem to be fixed by the [this fork of your code](https://github.com/deltaidea/gitdrive). That got the job done for me but you might look into joining forces. – Caleb Dec 15 '16 at 08:58
10

gdoc is not set up for exporting revision history source.

Google drive does have an API to access all the revisions here. That provides an easy way to download all the revisions. Then you can create a script to add them one by one to git. There are some problems with the revision history see here.

Whitecat
  • 3,882
  • 7
  • 48
  • 78
  • This is very useful research; thank you! Authoritative word on it not being designed for more than reverting to prior states suggests I may be better off rethinking the project, though it might be interesting to experiment with the drive API, if it also applies to all GDocs. – ecmanaut Jan 08 '13 at 23:05