删除git中的提交历史 [英] removing commit history in git
问题描述
我正在玩 heroku
和 django
。要在上托管我的Django应用, heroku
,我不得不多次来回更改许多文件( settings,urls,requirements.txt
等)(以便得到东西)右)。因此,回购中有很多提交。问题是我在 github
上有稳定版本的代码(在对heroku进行特定修改之前)现在,如果我将所有要使应用程序在 heroku
上运行的提交提交到我的 github
,这将看起来很丑。
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
.
因此,我想删除所有这些提交,并返回到较旧的稳定版本。然后,我可以添加 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来自 github
,然后添加 heroku
特定更改。然后提交,推送到 github
,推送到 heroku
。
1.pull from github
and then add heroku
specific changes.Then commit,push to github
,push to heroku
.
2。在 gitk
中,我可以选择提取上一次Heroku之前的提交,右键单击并执行'Reset master branch to here'。然后进行 heroku
相关更改,提交并推送到 github
,推到 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
.
这是正确的方法吗? Heroku之前的提交是ver6,而我当前的提交是ver10,我做了4个不必要的提交。我需要将它们擦干净,然后进行下一个提交ver7。
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.
有人可以请教吗?
推荐答案
- 执行git pull以获取最新版本。
- git rebase --interactive 修改后的分支。选择壁球作为第一个以外的所有东西,只进行一次提交。 (将提交消息更改为明智的内容)。
- git cherry-pick在任何要与稳定分支合并的开发分支上进行一次提交。
- 合并并推送
- 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
这篇关于删除git中的提交历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!