简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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