我想将react和spring项目上传到同一个存储库中。当我试图推另一个后推一个时,我会犯这个错误。当我使用-强制时,另一个项目的代码被删除。如何将两者存储在存储库中?
bar1s@DESKTOP-C8L726O MINGW64 ~/Desktop/spring/auction-project (master)
$ git push -u origin master
To https://github.com/cevikbaris/Auction-Website.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/cevikbaris/Auction-Website.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.发布于 2022-06-17 21:17:56
您只能将这两个项目存储在同一个存储库中,或者存储在存储库上的两个不同的分支上,或者将两个项目存储在同一个目录中。
这里的问题是:当您推送一个项目时,会对在线存储库进行更改,然后您的本地存储库中就没有了这些更改。因此,您不能推送,因为在这种情况下,git不知道如何处理不同的代码。
如何修复这个
解决方案1:
将两个项目存储在相同的目录中。要快速解决问题,只需运行
git pull在尝试推动你的项目之前。
这将将更改拉到您的本地存储库,如果您有任何同名目录,则可能会造成混乱。
但你可以推。
解决方案2:
为两个项目创建不同的分支。
使用以下命令执行此操作:
git branch <branch name> //create a new branch
git branch //view your branches
git switch <branch name> //switch to the specified branch然后,您可以将项目推送到单独的分支上,同时仍然在同一个存储库中工作。
参考资料:
https://stackoverflow.com/questions/72643941
复制相似问题