在 Heroku 上清理 git 仓库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10451330/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:37:24  来源:igfitidea点击:

Clean git repo on Heroku

githerokurepositoryreset

提问by Paul

The situation is as follows:

情况如下:

We have some project which persists on Github, and deploy it to Heroku, which has its own mini-Git. Some changes were applied directly to Heroku (cloned repository from Heroku, made changes and pushed). In a meanwhile the master branch on Github has gained also some changes.

我们有一些项目持续存在于 Github 上,并将其部署到 Heroku,后者拥有自己的迷你 Git。一些更改直接应用于 Heroku(从 Heroku 克隆存储库,进行更改并推送)。与此同时,Github 上的 master 分支也发生了一些变化。

Now when I want to push the main repository to Heroku, pushing fails because commits on Heroku are out of sync with local commits.

现在,当我想将主存储库推送到 Heroku 时,推送失败,因为 Heroku 上的提交与本地提交不同步。

I do not want to merge with changes on Heroku - I just want them to vanish.

我不想与 Heroku 上的更改合并 - 我只想让它们消失。

Is there some way to clean git repository on Heroku to push then my local repo from the very beginning?

有什么方法可以清理 Heroku 上的 git 存储库,然后从一开始就推送我的本地存储库?

I do not want to destroy application and recreate it again because it has some paid services and I am just an collaborator.

我不想销毁应用程序并重新创建它,因为它有一些付费服务,而我只是一个合作者。

回答by Jon Mountjoy

You can just use the -fflag in git (it's a standard git flag) to force the push. See the side note in the Dev Center Gitdoc. This will overwrite those changes you've made on Heroku obviously.

您可以只使用-fgit 中的标志(它是标准的 git 标志)来强制推送。请参阅开发中心Git文档中的附注。这显然会覆盖您在 Heroku 上所做的更改。

回答by Steve Eynon

Install the Heroku Repo pluginand use it to reset the remote git repo.

安装Heroku Repo 插件并使用它来重置远程 git repo。

First delete the git repo on the server:

首先删除服务器上的git repo:

> cd /my-project/
> heroku plugins:install heroku-repo
> heroku repo:reset

Then re-initialise your local git repo by deleting and recreating it:

然后通过删除并重新创建它来重新初始化您的本地 git 存储库:

> cd /my-project/
> rm -rf .git
> git init
> heroku git:remote -a <appname>

Where <appname>is name of your app in heroku.

<appname>您的应用程序在 heroku 中的名称在哪里。

The 2 repos (local and remote) should now be empty and in sync.

2 个存储库(本地和远程)现在应该是空的并且是同步的。

回答by courtsimas

Try going to https://github.com/heroku/heroku-repoand using that plugin to remotely clean things up.

尝试访问https://github.com/heroku/heroku-repo并使用该插件远程清理。

回答by Todd A. Jacobs

If your Heroku push is failing because it's not a fast-forward commit, and you're not trying to do anything funky with your history, it's very simple:

如果您的 Heroku 推送失败,因为它不是快进提交,并且您没有尝试对您的历史做任何时髦的事情,这很简单:

  1. Ensure that your non-Heroku repository is defined as a remote.
  2. Fetch all remotes.
  3. Merge your other repository into your local Heroku clone using the recursive strategy with the "theirs" strategy option.

    git merge -X theirs remotes/origin/master
    
  4. Push with the --forceoption to make a non-fast-forward commit to your upstream Heroku repository.

  1. 确保您的非 Heroku 存储库被定义为远程存储库。
  2. 获取所有遥控器。
  3. 使用递归策略和“他们的”策略选项将您的其他存储库合并到您的本地 Heroku 克隆中。

    git merge -X theirs remotes/origin/master
    
  4. 使用对--force上游 Heroku 存储库进行非快进提交的选项推送。

On the other hand, if you're really trying to purge history, you have some other options.

另一方面,如果您真的想清除历史记录,您还有其他一些选择。

  • Remove all but the first commit from your history (easiest).

    git reset --hard $(git log --pretty=oneline | tail -n1 | cut -d ' ' -f1)
    git push --force
    
  • Create an empty master branch.
  • Use git-filter-branch.
  • 从历史记录中删除除第一次提交之外的所有内容(最简单)。

    git reset --hard $(git log --pretty=oneline | tail -n1 | cut -d ' ' -f1)
    git push --force
    
  • 创建一个空的 master 分支
  • 使用git-filter-branch

Personally, I'd recommend keeping your history and fixing the fast-forward issue as a best-practice, but you certainly have options if you want to modify your history aggressively. Git is very flexible in that regard.

就个人而言,我建议保留您的历史记录并作为最佳实践修复快进问题,但如果您想积极修改历史记录,您当然可以选择。Git 在这方面非常灵活。

回答by Aerendir

You can also simply use the heroku's app versioning system. Going to "Activity" you have the complete history of the project: rollback to the first activity and the repo should be completely cleaned, coming back to its state when the app was originally created on Heroku.

您也可以简单地使用 heroku 的应用程序版本控制系统。转到“活动”,您将获得项目的完整历史记录:回滚到第一个活动,并且应该完全清理存储库,回到最初在 Heroku 上创建应用程序时的状态。