从我的git历史记录中删除4次提交 [英] Remove 4 commits from my git history

查看:103
本文介绍了从我的git历史记录中删除4次提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经做了一些提交,并将它们推送到我的存储库中.然后我做了一个请求请求,但是我意识到我不想在请求请求中包含一些提交.

I have done some commits and pushed them into my repository. Then I did a pull request but I realized there are some commits I don't want to be in the pull request.

它们看起来像这样:

My commits look like this:

Correct HTML    
ab1c41c 

HTML escaping   
8b38955 

Merge branch 'master' into internationalized    
2854662

Modified config 
b942f13 

tried pushing   
b73d792 

Added assets    
f20106e 

Added config    
408118f 

Fixed views conflicts   
86f2509 

added layouts   
da27e11 

Fixed layout markup
92d6bcc 

如果我想摆脱这些提交:

If I want to get rid of these commits:

Modified config 
b942f13 

tried pushing   
b73d792 

Added assets    
f20106e 

Added config    
408118f 

我该怎么做?请注意,我想保留这些要早于我要删除的那些:

How do I do it? Notice that I want to keep these ones which are before in time that the ones i want to delete:

Correct HTML    
ab1c41c 

HTML escaping   
8b38955

推荐答案

您可以执行交互式变基.

假设您的头位于示例中的ab1c41c,请按如下所示调用rebase

Assuming your head is at ab1c41c from your example, invoke the rebase as follows

git rebase -i HEAD~7

这告诉git您要操纵最近的8次左右的提交.您将被提交到列表中并提交一些说明,并进入到您的编辑器中.

This tells git you want to manipulate the last 8 or so commits. You'll be dropped into your editor with a listing of the commits and some instructions.

删除包含要删除,保存和退出的提交的行. Git将执行重新设置,仅此而已.

Delete the lines that contain the commits to remove, save and quit. Git will preform the rebase, and that's it.

请牢记,由于存在基准,如果要推送到同一分支,则需要传递选项--force.

Keep in mind, because of the rebase, if you want to push to the same branch you'll need to pass the option --force.

免责声明:重新设置基础和强行执行可能会导致您失去工作或惹恼他人,因此请确保您了解自己在做什么. :)

Disclaimer Rebasing and force pushing can cause you to lose work or piss people off, so just make sure you understand what you're doing. :)

这篇关于从我的git历史记录中删除4次提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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