简体   繁体   English

git:撤消上次提交并返回当前版本

[英]git: undo last commits and go back to current version

在此处输入图片说明

My dog checked in an error in my project and I recognized it later.我的狗在我的项目中检查了一个错误,后来我认识到了它。 Now I would like to go back to an commit and say that this should be the new base.现在我想回到一个提交并说这应该是新的基础。 The problems are in the commit of the red line.问题出在红线的提交上。 The correct version is the commit that is currently selected.正确的版本是当前选择的提交。 How can I remove the topmost and the red commit?如何删除最顶层和红色提交?

I can't see the image over here but my guess is that you don't want the changes from a revision that is part of the history of your current branch, right?我看不到这里的图像,但我的猜测是您不希望修订版中的更改是当前分支历史记录的一部分,对吗? If you actually want those changes removed from the history of the branch and removed from the working tree (for example, your dog added a line that you don't want on your project..... quite skillful your dog.... should consider going out on a circus with him), then you should just remove it from the history of the branch.如果您确实希望将这些更改从分支的历史记录中删除并从工作树中删除(例如,您的狗在您的项目中添加了一条您不想要的行......你的狗非常熟练......应该考虑和他一起去马戏团),那么你应该把它从分支的历史中删除。 Let's suppose your branch is called test and the revision you want to remove is 3 revisions before test tip.假设您的分支名为 test 并且您要删除的修订版是测试提示之前的 3 个修订版。

git checkout test~4 # go back to the revision _before_ the one you want to delete
git cherry-pick test~3..test # cherry pick the revisions after the one you want to delete
git branch -f test # move test pointer
git checkout test # checkout test

At this point what your dog did should be gone from the branch.此时你的狗所做的应该从树枝上消失。

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

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