如何将 Heroku git 存储库重置为其初始状态? [英] How do I reset a Heroku git repository to its initial state?

查看:29
本文介绍了如何将 Heroku git 存储库重置为其初始状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 git 存储库中有一个 Web 应用程序.由于历史原因,Web 应用程序不在存储库的根目录中,它位于名为 website 的文件夹中.除此之外还有一些其他文件夹,所以我有以下结构:

I have got a web application within a git repository. Due to historic reasons the web application is not at the root of the repository, it is within a folder called website. Beside that there are some other folders, so that I have got the following structure:

myApp
+- .git
+- otherFolder1
+- otherFolder2
+- otherFolder...
+- otherFolderN
+- website

该网站在 Heroku 上运行.由于 Heroku 要求您的 Web 应用程序位于 git 存储库的根目录,直到现在我使用了一个构建过程,该过程将 website 文件夹复制到一个完全不同的(外部)文件夹中,该文件夹具有自己的 git 存储库.然后我就可以从那里推送到 Heroku,一切都很好.

The website is run on Heroku. As Heroku demands that your web application is at the root of a git repository, until now I used a build process which copied the website folder to a completely different (external) folder with its own git repository. Then I was able to push from there to Heroku and everything was fine.

现在,由于 git 包含 subtree 命令,这不再是必需的,因为我可以直接从我的初始文件夹推送,但只是 website 子文件夹,使用:

Now, since git includes the subtree command this is not necessary any longer, as I could directly push from my initial folder, but just the website sub-folder, using:

git subtree push --prefix=website heroku master

基本上,这很完美.我只有一个问题:由于之前对 Heroku 的提交来自完全不同的 git 存储库,因此两者的历史记录彼此不匹配 - 因此 Heroku 检测到非快进推送,并拒绝 subtree 推.

Basically, this works perfectly. I only have one problem: As the previous commits to Heroku came from a completely different git repository, the history of both doesn't match each other - so Heroku detects a non-fast-forward push, and rejects the subtree push.

那么我该如何处理?

  • 想法 1:强制推送.试过了,但不起作用,因为 git subtree push 没有 --force 选项(或任何类似的东西).
  • 想法 2:清除 Heroku 的存储库并重新从头开始.
  • Idea 1: Force push. Tried that, but doesn't work as git subtree push does not have a --force option (or anything similar).
  • Idea 2: Clear Heroku's repository and start from scratch again.

我很想采用想法 2,但我不知道如何实现.

I'd love to go with idea 2, but I have no idea of how to achieve this.

我的第一个方法是运行 git push heroku :master,但 Heroku 检测到并拒绝它.

My first approach was to run a git push heroku :master, but Heroku detects this and denies it.

当然,我可以销毁应用程序并重新创建它,但是所有域分配和附加组件也都消失了,我想避免这种情况.

Of course, I could destroy the app and recreate it, but then all domain assignments and add-ons are gone as well, and I'd like to avoid that.

还有其他想法吗?

推荐答案

你可以嵌套 git 命令来执行强制推送.

You can nest git commands to execute force push.

对于您的情况,命令将是:

For your case the command will be:

git push heroku `git subtree split --prefix website master`:master --force

这篇关于如何将 Heroku git 存储库重置为其初始状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆