如何下载以前保存的 Google Apps 脚本修订版?

How do I download previous saved revisions of a Google Apps Script?

我仍在尝试从中恢复 somehow 'loosing' a Google Apps Script when I created a copy of the script to fork the code to another project... My thought was to attempt to download older revisions of the Google Apps Script via the drive API, but this page 表明这可能是不可能的。

Actions such as versioning, publishing or executing the script are not available through the API.

所以我还是尝试了,唉,这个错误发生了...

<HttpError 400 when requesting 
https://www.googleapis.com/drive/v2/files/..snipped../revisions?alt=json
returned "File does not support revisions">

所以没有机制可以下载以前版本或 "Revisions" Google Apps 脚本吗?我希望能够访问 script.google.com 界面中显示的 'Revision 1':

这有点手动但是:

  • 创建另一个脚本项目
  • Include your original script as a library 在你的新脚本和 select v1
  • 在新脚本中添加一些使用您的“库”的代码
  • 使用脚本编辑器调试器进入库,您应该会看到正确版本的代码

例如,如果您的库名为“MyOldCode”,请在您的新脚本中包含这样的代码:

function getOldCode() {
  var a = MyOldCode.anExampleFunction()
}

在“var a”行下方放置一个断点,运行 使用调试器获取 OldCode(),然后进入 anExampleFunction()。这将打开您的旧代码的一个文件,您可以将其复制并粘贴到其他地方。

然后你可以拼凑v1.

编辑2019-04-11:还有Romain's function for accessing old versions.

编辑 2022-05-05:有了 V8 和新编辑器,我再也找不到进入图书馆的方法了。 Rhino 报服务器错误,V8 忽略“step in”。

仅供参考,Apps 脚本 API 可以从以前的版本号获取项目文件: https://developers.google.com/apps-script/api/reference/rest/v1/projects/getContent

如果您希望在 Apps 脚本 CLI 中看到这个,clasp,就像 clasp pull 3,我相信我可以添加这个功能。 https://github.com/google/clasp/ 只需提交一个新问题。

格兰特是正确答案。扣是方式。我只是想更新 clasp 当前状态的命令

clasp pull --versionNumber 12