11

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! :-)

Lisa Anne
  • 4,482
  • 17
  • 83
  • 157
  • 1
    Please check this answer, looks like it's what you want to do: http://stackoverflow.com/questions/4114095/revert-to-a-previous-git-commit – jbarrueta Apr 25 '15 at 07:53

2 Answers2

6

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!

SantanuMajumdar
  • 886
  • 1
  • 5
  • 20
5

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.

Mohammad AbuShady
  • 40,884
  • 11
  • 78
  • 89