Heroku - git push/deployment 期间出错,此代码的相同版本已经构建

Don*_*asa 6 java git github heroku heroku-cli

我在将 springboot 应用程序部署到 Heroku 时遇到问题。运行后git push heroku master,我遇到以下错误:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  9.350 s
[INFO] Finished at: 2020-12-22T06:33:14Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project audit: Fatal error compiling: invalid target release: 11 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :audit
remote:  !     Push rejected, failed to compile Java app.
remote: 
remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built:             31199a7acec03a3cb614ebaaf6c7720cee6684bd
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 31199a7acec03a3cb614ebaaf6c7720cee6684bd
remote:  ! at least twice. One common cause of this behavior is attempting to deploy code     from a different branch.
remote:  !
remote:  ! If you are developing on a branch and deploying via git you must run:
remote:  !
remote:  !     git push heroku <branchname>:main
remote:  !
remote:  ! This article goes into details on the behavior:
remote:  !   https://devcenter.heroku.com/articles/duplicate-build-version
remote: 
remote: Verifying deploy...
remote: 
remote: !   Push rejected to tesda8app.
Run Code Online (Sandbox Code Playgroud)

我不知道为什么会发生这个错误。我有两个远程存储库,用于推送我的代码,一个来自 Heroku,另一个来自 Github。我已经根据这个问题的答案尝试了下面的命令,Heroku:如果你在一个分支上开发并通过 git 部署,你必须运行:

git push heroku master:main
Run Code Online (Sandbox Code Playgroud)

但错误仍然存​​在。我可以在 Heroku CLI 上尝试任何命令来解决这个问题吗?

Don*_*asa 9

经过几次尝试,我认为问题的原因可能是命令被中断 git push heroku master,然后重新执行同一命令,导致出现以下错误:

remote:  !     Push failed
remote:  !
remote:  ! ## Warning - The same version of this code has already been built:             31199a7acec03a3cb614ebaaf6c7720cee6684bd
remote:  !
remote:  ! We have detected that you have triggered a build from source code with version 31199a7acec03a3cb614ebaaf6c7720cee6684bd
remote:  ! at least twice. One common cause of this behavior is attempting to deploy         code     from a different branch.
remote:  !
Run Code Online (Sandbox Code Playgroud)

所以我所做的是,我推送了另一个提交,然后重试相同的命令git push heroku master,这导致了成功的部署。

另外,感谢RainXCat 的回答和见解,现在我知道 Heroku 不允许在同一目录/文件夹上有两个 git 存储库。


Rai*_*Cat 5

我在同一天遇到了与您相同的错误,我不知道这是否是您正在寻找的答案,但我以某种方式解决了该问题。我正在制作 Django-Rest-Api。

原因

你已经在同一个文件夹/目录中创建了两个 git 存储库,并将相同的代码推入它们的头部,但不知何故Heroku不希望你这样做。 记住没有两个 git repo 处于同一级别

关于那git push heroku master:main件事

Heroku 仅从 main/master 分支部署代码,因此如果您从 master 以外的分支推送,则必须像使用 with 一样使用它git push heroku <new branch>:main,使用:mainwithmaster是没有意义的(相同)。

解决方案

选项1(不适合我)

我不记得从哪里得到这个,但你必须创建一个新的 git 分支,做

git branch <new branch>
git checkout <new branch>
git add .
git commit -am "commit message"
git push heroku <new branch>:main
Run Code Online (Sandbox Code Playgroud)

但它给出了相同的错误,因为你的目录中仍然有两个 git repo。

你可以像这样删除仓库。

rm -rf .git
Run Code Online (Sandbox Code Playgroud)

我建议您在临时副本上进行实验。

选项2(为我工作)

我所做的就是复制里面的所有文件,用不同的名称创建一个新文件夹,粘贴所有文件,删除旧文件,然后将新文件重命名为旧文件。通过这样做,您将拥有一个 git 免费目录,然后您可以使用该git init方法简单地创建一个新的存储库。

这是你应该如何创建

git init
heroku create
git add .
git commit -am "initial commit"
git push heroku master
Run Code Online (Sandbox Code Playgroud)

这应该可以解决错误,它已经为我解决了,所以我不太可能再继续处理它,但如果我的答案以任何方式不正确,请告诉我。