Clean git repo on Heroku

霸气de小男生 提交于 2019-12-03 04:41:01

问题


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.

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

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

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

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


回答1:


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




回答2:


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

First delete the git repo on the server:

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

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

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

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

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




回答3:


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




回答4:


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:

  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 --force option to make a non-fast-forward commit to your upstream Heroku repository.

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.

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.




回答5:


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.



来源:https://stackoverflow.com/questions/10451330/clean-git-repo-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!