【问题标题】:How to find the github repository associated with a heroku app?如何找到与 Heroku 应用关联的 github 存储库?
【发布时间】:2019-11-03 09:32:24
【问题描述】:

这个问题很简单。我部署了一个 heroku 应用,但我找不到它的源代码。

我们如何通过 heroku CLI 或 heroku Web 界面检索给定 heroku 应用程序的 github 存储库 url?

编辑:是的,这已经困扰我一年多了

我尝试过的

我试过heroku git:clone -a APP-NAME 将存储库(从heroku?)复制到本地。在cd进入之后,尝试get the github remote url

git config --get remote.origin.url

但返回空白。我也试过了

git remote show origin  
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

【问题讨论】:

  • 您确定存在一个与该应用关联的 GitHub 存储库吗?可能没有。最初是谁部署的?
  • @Chris 我部署了它,它肯定是从 github repo 部署的(我不知道其他方式)。我只是不知道这个应用程序来自哪个 github repo,并且不想删除它以防万一那里有重要的东西。我认为 heroku 应该在某处声明 github url,这将是一个简单的解决方案,但我似乎无法找到它
  • 所以...您从 GitHub 部署它,但您不记得从哪个特定存储库部署?您可以使用heroku releases 查看提交哈希。我不确定是否有任何显示 GitHub 存储库的内容,但请尝试在那里查看。
  • @Chris 是的。如果您有数百个应用程序,这不难想象。 Heroku 的优势在于它使部署应用程序变得微不足道(例如,从笔记本电脑到 git 到 heroku 大约需要 30 秒)。这对于快速部署微服务等非常有用。每隔一段时间,我就会清理未使用或必要的应用程序,这直到现在都不是问题,因为大多数应用程序的根 url 都有一些东西。但在一种情况下,它没有,我不想删除它,直到我确定它不重要。
  • @Chris Running heroku releases -a myappname 返回预期输出(但没有提及 repo)。我尝试git log -n 1 9643b02d -a myappname(其中提交是第一个命令输出中最新的),并得到fatal: not a git repository (or any of the parent directories): .git

标签: github heroku


【解决方案1】:

请参阅documentation 下载您的代码。 Heroku 允许您从他们的服务器克隆 git 存储库 - 只要您可以访问 Heroku 中的应用程序,您就可以看到已部署的确切代码。

【讨论】:

  • ...but "Heroku 应用程序的 Git 存储库仅用于部署目的。官方不支持从该存储库克隆作为一项功能,只能作为最后的手段尝试。不要将此存储库用作您应用的规范“源”存储库。而是使用您自己的 Git 服务器或 GitHub 等版本控制服务。”
  • 我刚试过heroku slugs:download -a myapp 并得到› Warning: slugs:download is not a heroku command.
【解决方案2】:

我刚刚尝试了heroku slugs:download -a myapp 并得到了

Warning: slugs:download is not a heroku command.

您需要先安装heroku/heroku-slugs 插件,才能识别该命令。

heroku plugins:install heroku-slugs

但是先试试,就像你做的那样

heroku git:clone -a APP-NAME

然后git log -1: 将为您提供最新提交的 SHA1。

然后您可以在 GitHub 上执行 Commit search by hash。
示例:

https://github.com/github/gitignore/search?q=hash%3A124a9a0ee1d8f1e15e833aff432fbb3b02632105&type=Commits


OP stevec 提到 in the comments 使用“How to clone all repos at once from GitHub?”来处理 100 多个存储库,并且(关键地)也下载私有存储库(不仅仅是公共存储库)。
也就是说:编写一个 bash 脚本,克隆我帐户上的每个存储库,并以某种方式搜索特定的 SHA。

我建议一个简单的git log -1 SHA,或者;,在“How to check if the commit exists in a Git repository by its SHA-1”之后:

git rev-parse -q --verify "$sha^{commit}" > /dev/null

OP 补充说:

我意识到您的初始解决方案确实有效(即使对于私人回购)。

heroku git:clone -a APP-NAME
git log -1, 
https://github.com/search?q=hash%3A<SHA>

【讨论】:

  • 谢谢!这一切都说得通。但是在获得提交 SHA 并搜索它之后,我看到了We couldn’t find any commits matching ..。我做了一些修改以确保我正在搜索所有 github,尝试使用 hash:... 搜索框并以几种方式更改 URL(尝试 : 和 %3A),但我似乎没有能够得到任何结果。我会尝试git log -2(等等),希望有一场比赛。如果您有任何其他想法,我们将不胜感激!
  • @stevec 是您最初的私有仓库吗?搜索只能在公共回购的主分支上工作。
  • 我猜可能是这样。我在想这里的一个解决方案可能是编写一个 bash 脚本来克隆我帐户上的每个存储库并以某种方式搜索特定的 SHA。如果一切顺利,我想这不会花那么长时间。你知道任何更好/更简单的方法吗?
  • @stevec “以某种方式搜索特定的 SHA。”:在每个克隆的存储库中添加一个 simple git log &lt;sha&gt; 就足够了。
  • 谢谢!我将尝试调整 this 以处理 > 100 个存储库并(关键)也下载私有存储库(不仅仅是公共)
猜你喜欢
  • 1970-01-01
  • 2012-08-22
  • 2012-01-20
  • 1970-01-01
  • 2014-07-28
  • 2019-03-06
  • 2018-11-02
  • 2013-11-20
  • 1970-01-01
相关资源
最近更新 更多