Heroku:src refspec master不匹配任何内容。

139

我正在Heroku上进行托管。当我提交(push)时:

git push master Heroku

我遇到了一个错误:

error: src refspec master does not match any.
error: failed to push some refs to 'git@heroku.com: etc ...'

6
如果你遇到了上述错误,可能是因为分支名称不正确,所以对于其他面临相同问题的人来说,双重检查分支名称会很有帮助。 - Persistent Plants
2
这种情况也会发生在你还没有提交任何内容的时候。你在添加后是否进行了commit操作? - seb
27
对于任何来到这里的人,我也经历过同样的事情,造成这种情况的原因是 git 将 master 重命名为 _main_,根据 此链接 ,从 2020 年 10 月 1 日开始,可能是 Heroku 过早行动了 ¯\(º.º)/¯。 - Scaramouche
尝试从头开始运行它:git config --global - Memphis Meng
16
也许需要运行命令 git push heroku main - Sam Murphy
26个回答

0
  1. 检查是否已将Heroku添加为远程:git remote -v 您应该看到类似于以下内容:

heroku https://git.heroku.com/yourapp.git (获取) heroku https://git.heroku.com/yourapp.git (推送)

  1. 如果没有,则设置远程 - git remote add heroku git@heroku.com:MyApp.git(在旧版本的Git中)或heroku git:remote -a example-app(在新版本的Git中)

  2. git push heroku master(旧版Git) git push heroku main(新版Git)


0

请确保您推送的应用名称与Heroku中的相同。


1
目前你的答案写得不够清晰,请进行[编辑]以添加更多细节,以帮助其他人理解这个问题。你可以在帮助中心找到更多编写好答案的信息。 - Community

0

如果上述解决方案无效,请检查隐藏的.git文件夹。在.git文件夹中,检查名为packed-refs的文件, 它应该有一个哈希键引用到refs/remotes/heroku/main。 如果没有,则可以按照以下步骤操作:

  • 步骤1:登录Heroku CLI
  • 步骤2:运行命令heroku git:clone -a your-app-name
  • 步骤3:执行git push

要获取Heroku应用程序列表,请运行以下命令 heroku apps


0

我也遇到了同样的问题。 对我来说,问题出在我没有正确地登录 git。 在将代码推送到主分支之前,必须首先使用命令 git commit -m "My first commit" 进行初始提交。 当您尝试执行此操作时,可能会得到以下响应(就像我得到的一样):

git: fatal unable to auto-detect email address (got "some wrong email").

如果您得到了这个响应,那么现在必须使用以下命令输入所需的 git 电子邮件和用户名:

git config --global user.email "you@example.com"

git config --global user.name "Your Username"

完成后,请再次尝试推送命令

git push heroku master

现在应该可以正常工作。


0

我在将本地存储库的副本推送到GitHub存储库后遇到了这个问题。

在此之前,从我的本地存储库运行git push heroku master以部署到Heroku一直很顺利。

然而,在推送到GitHub之后,git push heroku master开始出现error: src refspec master does not match any错误消息,我不得不使用git push heroku main才能成功部署。

显然,将副本推送到GitHub会将本地存储库的分支名称从master更改为main


0
对我来说,问题是有两个锁定文件package-lock.jsonyarn.lock。删除其中一个解决了问题。以下是错误信息:
 !     Two different lockfiles found: package-lock.json and yarn.lock
       Both npm and yarn have created lockfiles for this application,
       but only one can be used to install dependencies. Installing
       dependencies using the wrong package manager can result in missing
       packages or subtle bugs in production.
       - To use npm to install your application's dependencies please delete
         the yarn.lock file.
         $ git rm yarn.lock
       - To use yarn to install your application's dependences please delete
         the package-lock.json file.
         $ git rm package-lock.json

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接