简体   繁体   中英

Git: how to go back to a previous commit

I am in this situation in master :

     --c1--c2--c3--c4

I am in c4 , but I don't like it, I would like go back to c1 and work on that in master:

        ______________   
       /              \
    --c1--c2--c3--c4   c6

Please how do I achieve that?

Thanks! :-)

Do this -

git checkout c1

Return to master branch

git checkout master

git checkout - , which will checkout the previous branch or commit that HEAD pointed at.

Let me know if it helps.

Thanks!

An easy way i use to step backwards in a number of steps is git checkout HEAD~[number]

If i want to go back for 3 steps, you'll write git checkout HEAD~3 if you ignore the number then git will assume it's 1 step

Of course you can always just take the hash and checkout to that hash

git checkout ABC123

Note that you will become in a detached head state, meaning there's no branch pointing to this hash, so you either git reset to drop all the other changes and make this commit your latest, or git branch to create a new branch name to make sure your commits don't become unreachable.

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