问题
I was playing around with heroku
and django
.To host my django app on heroku
,I had to change many files(settings,urls,requirements.txt
etc) so many times back and forth (so as to get things right) .As a result there are so many commits in the repo.Problem is that I have the stable version of the code(before the heroku specific modifications were done) on github
and now it would look ugly if I push to my github
all those commits which I did to get app working on heroku
.
So,I want to remove all those commits,and get back to the older stable version.Then I can add the heroku
specific modifications and just do one commit.The way I see it ,I can do
1.pull from github
and then add heroku
specific changes.Then commit,push to github
,push to heroku
.
2.In gitk
,I can select the last pre-heroku commit, right click and do 'Reset master branch to here'.Then make heroku
related changes,commit ,push to github
,push to heroku
.
Which is the correct way to do this?Suppose the pre-heroku commit was ver6, and my current commit is ver10,there are 4 unnecessary commits which I made.I need to wipe them clean ,and make the next commit ver7.
Can someone please advise?
回答1:
- Do a git pull to get the latest version offline.
- git rebase --interactive your branch with modifications. Select squash for everything except the first one to make just one commit. (change the commit message to something sensible)
- git cherry-pick that one commit on whatever development branch you will merge with your stable branch.
- merge and push
回答2:
Method is pretty similar to that in Github which had been mentioned here. Though I will rewrite the answer for Heroku.
In order to delete commit history
- Create a new branch and checkout to it
git checkout --orphan branch_new
- Add all files
git add -A
- Commit
git commit -m "Deleting commit history"
- Delete master branch
git branch -D master
- Rename the branch to master
git branch -m master
- Force push the update to repository
git push -f heroku master
来源:https://stackoverflow.com/questions/14755940/removing-commit-history-in-git