解决此问题的另一种方法是广泛了解与 heroku 应用关联的 .git/config 文件正在做什么,并进行必要的调整。
1.从您的 heroku 项目的根目录打开 .git/config。
您的 git 配置文件可能看起来像这样,尤其是当您在机器上同时使用几个 heroku 帐户时。
git@heroku.{heroku.account} 出现,而不是 git@heroku.com,因为您的 ~/.ssh/config 文件中的配置。应该更新对heroku-app-8396.git 的引用以匹配您的heroku 项目名称。您拥有的每个 heroku 帐户都应该在 ~/.ssh/config 文件中有一个条目。显然,与此 heroku 项目关联的 heroku 帐户应该显示在您的 .git/config 文件中。
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@heroku.heroku.account:heroku-app-8396.git
[remote "heroku"]
fetch = +refs/heads/*:refs/remotes/heroku/*
url = git@heroku.heroku.account:heroku-app-8396.git
[branch "master"]
remote = origin
merge = refs/heads/master
[heroku]
account = heroku.account
2.当我运行git pull heroku master时,一切似乎都运行良好。
3.当我运行heroku logs时,我收到一条错误消息:
$ heroku ps
! No app specified.
! Run this command from an app folder or specify which app to use with --app APP.
为什么?
据我所知,heroku 命令似乎不知道如何处理{heroku.account} 引用。如果我们将这些引用更改为com(这是您不使用“帐户”heroku 插件时的默认值),heroku 命令再次工作,但现在我们的git 调用表明存在不同问题:
$ git pull heroku master
! Your key with fingerprint d6:1b:4c:48:8c:52:d4:d6:f8:32:aa:1a:e7:0e:a2:a1 is not authorized to access smooth-robot-8396.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决此问题的一种方法是为git 定义一个遥控器,为heroku 定义一个遥控器,然后告诉heroku 使用哪个遥控器。
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = false
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@heroku.heroku.account:heroku-app-8396.git
[remote "heroku"]
fetch = +refs/heads/*:refs/remotes/heroku/*
url = git@heroku.heroku.account:heroku-app-8396.git
[remote "heroku-app"]
fetch = +refs/heads/*:refs/remotes/heroku/*
url = git@heroku.com:heroku-app-8396.git
[branch "master"]
remote = origin
merge = refs/heads/master
[heroku]
remote = heroku-app
account = heroku.account
我喜欢在将内容推送到遥控器时显式指定遥控器,因此 heroku 遥控器就是为此而设计的,即使此配置也支持使用默认值(例如 git push)进行推送/拉取。我创建了一个新的远程 'heroku-app' 并添加了remote = heroku-app 来告诉heroku 使用一个在URI 中不包含heroku 帐户的远程。
现在我可以随意运行git 和heroku 命令了。