如何将 gdoc 的修订历史导出到 git?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14222090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 08:00:10  来源:igfitidea点击:

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

gitgoogle-docsgoogle-sheetsgoogle-docs-apigoogle-spreadsheet-api

提问by ecmanaut

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?

我在 google docs 中有一个电子表格,我想将其集成到 git 工作流程中(并推送到 github)。是否有任何工具(甚至可以识别 gdoc 版本的库)可以做到或帮助我做到这一点?

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

我有一些基于google_spreadsheet gem 的旧 ruby​​ hack ,它可以读取和写入当前版本的 csv gdoc,但没有提取修订历史记录。

采纳答案by Whitecat

gdoc is not set up for exporting revision history source.

gdoc 没有设置为导出修订历史

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.

谷歌驱动器确实有一个 API 来访问这里的所有修订。这提供了一种下载所有修订的简单方法。然后你可以创建一个脚本将它们一一添加到git中。修订历史有一些问题,请参见此处

回答by larsks

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:

给定一个文档 ID,它将使用 Google Docs 文档的纯文本或 HTML 内容创建一个 git 存储库。这可以很容易地扩展到与其他文件类型一起使用。它在工作时看起来像这样:

$ 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 notintended to be a functional product.

这要求您通过 Google 设置必要的应用程序凭据。它不做任何错误检查。并且可能会吃掉你的金鱼。这是作为 API 的演示以及您如何做这样的事情;它并非旨在成为功能性产品。