简体   繁体   English

如何还原不是最新的提交

[英]How to revert a commit which is not the latest

I'm using Egit. 我正在使用Egit。 In one of my git project i had to preserve the latest commit but delete the previous commit. 在我的git项目之一中,我必须保留最新的提交,但要删除先前的提交。

For example, If HEAD points to latest commit. 例如,If HEAD指向最新提交。
Followed by previous commit. 随后是先前的提交。

Could anyone please let me know if this can be achieved ? 任何人都可以让我知道是否可以实现?

git revert would be an option: git revert将是一个选择:

git revert <commit>

It will create a new commit reverting changes. 它将创建一个新的提交还原更改。

Another option, preferably if you did not pushed your changes to a remote, is to use git rebase in interactive mode to put the commit you want to discard latest, then reset that commit 另一个选择(最好是如果您没有将更改推送到远程),最好是在交互模式下使用git rebase将要放弃的提交放到最新的位置,然后重置该提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM