简体   繁体   中英

How to recover the removed state after Git rebase

Here in "The Basic Rebase" example (Fig.3-27) it is shown how the experiment branch is rebased with master branche. As a result (Fig. 3-29) from C3 state patch is taken, applied that patch on C4 and C3' us created. Then, finally, C3 as a state is removed. My question is how to recover C3 state?

If you run git fsck --lost-found , you'll get a list of commits that are not reachable by tags or branches. The commits lost in the rebase will be on the list. Find the most recent one, and git checkout the corresponding hash. You can then tag it, make a branch, or whatever you like.

See here for a working example .

Assuming you want to get back to the commit state C3 , do

git reflog

search for commit C3 {line from reflog - e3eee5a HEAD@{4}: commit: C3 }, then

git reset e3eee5a

You will now be back to state C3 , keeping changes introduced by C4

To remove changes introduced by C4 , user reset --hard <commit>

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