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

拟墨画扇 提交于 2020-12-27 08:08:40

问题


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.


回答1:


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.




回答2:


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

  • https://github.com/larsks/gitdriver

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.



来源:https://stackoverflow.com/questions/14222090/how-do-i-export-the-revision-history-of-a-gdoc-to-git

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!