【问题标题】:Google Apps Script revision history only goes back a few daysGoogle Apps 脚本修订历史只能追溯到几天前
【发布时间】:2018-03-04 14:48:29
【问题描述】:

我有一整周都在处理的 Google Apps 脚本。我有 6 个保存的版本可以追溯到 9/18。我可以转到“管理版本”并查看所有版本,但无法恢复任何版本。

当我进入“查看修订历史”时,它只能追溯到 9/21。

有一点需要注意,这个项目的大部分内容都在 .html 文件中,而不是 .gs 文件中。有没有希望拿到之前版本的代码?

【问题讨论】:

  • 我知道你怎样才能得到所有的脚本代码。但不确定 HTML。
  • 如果代码是独立的 GAS 项目,可能需要查看 node-google-apps-script 以下载/上传本地计算机和 Google Drive 之间的所有代码文件 (.gs/html)。然后你可以使用 Git 或任何你喜欢的版本控制。谷歌的版本控制是可怕的。尝试获取以前的代码可能无济于事;省去了很多麻烦
  • 这是一个没有答案的问题@Alan Wells - 你知道吗?请告诉我们。我创建了命名版本,但没有找到有关恢复它们的文档。我看到了小的自动版本,但它们是逐个文件的。将所有文件恢复到同一时间点几乎是不可能的。 GAS 之外有哪些工具可以管理实际项目?显然,我们现在所拥有的还不能用于复杂的项目。
  • 查看新答案。

标签: google-apps-script


【解决方案1】:

从以前保存的版本中获取代码的唯一方法是使用 Apps Script API。代码编辑器无法加载以前保存的版本。
见:
https://developers.google.com/apps-script/api/reference/rest/v1/projects/getContent

可以指定版本号。如果没有指定版本号,则返回头版本。

如果您想使用 Apps Script 中的 Apps Script API,您需要使用 UrlFetchApp.fetch(url)

function getAppsScriptContent() {
  var accessTkn,id,options,projectID,response,url;

  id = "";//Enter the project id here

  url = "https://script.googleapis.com/v1/projects/{scriptId}/content";
  url = url.replace("{scriptId}", id);

  if (versionNumber) {
    url = url + '?versionNumber=' + versionNumber;
  }

  accessTkn = ScriptApp.getOAuthToken();

  options = {};
  options.muteHttpExceptions = true;//Make sure this is always set
  options.method = "GET";
  
  options.headers = {
      'Authorization': 'Bearer ' +  accessTkn
    }

  response = UrlFetchApp.fetch(url,options);

  if (!response || response .getResponseCode() !== 200) {   
      //Your error handling
  }

  fileContent = response.getContentText();
  
  try{
    fileContent = JSON.parse(fileContent);
    files = fileContent.files;
  }catch(e){
    
    //Error handling
  }

}

【讨论】:

  • 你如何运行这个?绑定到什么东西?
  • 它可以直接从代码编辑器运行。如果您需要定期运行它,那么您可以通过多种其他方式触发代码运行。
猜你喜欢
  • 1970-01-01
  • 2016-08-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多