Git:删除先前的提交,但保留最近的更改 [英] Git: remove earlier commit but keep recent changes

查看:75
本文介绍了Git:删除先前的提交,但保留最近的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的存储库中有一些提交:



  A  - 已添加功能A 
B - 已删除功能B
C - 已重新设计的功能C
D - 已添加功能D
E - 已添加功能D

其中E是我最近做出的提交。现在我想摆脱我使用功能C所做的更改,但我想保留使用D和E添加的更改。



我希望你能帮助我。



谢谢

解决方案

如果您只想 (正如在你的问题主体中指定的那样),而不是实际上移除提交(正如标题中所指定的),一个简单的选择是添加一个新的提交,完全相反早先的提交做了什么。



它不是万无一失的,它可能会导致冲突,因为自那之后所做的更改,但它不会改变历史,允许您记录逆转及其原因,并与其他工作副本一起玩。

git revert 是用来制作一组提交的这种邪恶双胞胎的工具。 p>

I got some commits in my repository:

like:

A - Added Feature A
B - Removed Feature B
C - Redesigned Feature C
D - Added Feature D
E - Added Feature D

Where E is the most recent commit I made. Now I want to get rid of the changes I made with feature C but I want to keep the changes added with D and E.

I hope you can help me.

Thank you

解决方案

If you only want to "get rid of the changes" (as specified in your question body) as opposed to actually "removing a commit" (as specified in the title), an easy option is adding a new commit, doing exactly the opposite of what the earlier commit did.

It's not foolproof and it can result in conflicts due to changes done since, but it doesn't alter history, allows you to document the reversal and its reasons, and plays well with other working copies.

git revert is the tool used to make such evil twins of a set of commits.

这篇关于Git:删除先前的提交,但保留最近的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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