我有这段代码,当环境启动时 (environment.rb) 会 pull 当前仓库的 git 版本。
APP_VERSION = `git describe --always --long` unless defined? APP_VERSION
让我打开网站,转到某个页面,看看网站上的版本是否正确。这段代码在 EngineYard 上运行,但在 Heroku 上,我在应用程序启动时得到了这个:
致命:不是 git 存储库(或任何父目录):.git
是否可以在 heroku 上运行 git describe
?
最佳答案
我认为你做不到;当您使用 git push
将您的应用程序部署到 Heroku 时,它似乎将其放入存储库,然后在没有 git 存储库的情况下干净地 check out 您的代码。您可以使用 heroku run bash
命令四处查看,看看那里有什么。这是我的一个应用程序的内容:
$ heroku run bash
Running `bash` attached to terminal... up, run.1
~ $ ls -a
. bin config.ru Gemfile lib public .rspec TODO.txt
.. .bundle db Gemfile.lock Procfile Rakefile script vendor
app config doc .gitignore .profile.d README spec
没有 .git
目录,所以 git
命令将不起作用。
如果您只想查看当前部署的版本,可以从应用程序的 Heroku 仪表板的“事件”选项卡下查看。 (https://dashboard.heroku.com/apps/[your app name]/activity
) 但我不确定如何将 git
版本添加到您的应用程序中代码,以便您可以将其显示为应用的一部分。
关于ruby-on-rails - 我可以在 heroku 应用程序的 environment.rb 中运行 `git describe` 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13459142/