1
      D  
     /  
A-B-C-E

Branch D is my current working directory, however, I want to 'clone' C again, make some changes and commit them to create E without having to change anything I did in D. Then I can continue to develop on D. How can I accomplish this?

Fred Foo
  • 355,277
  • 75
  • 744
  • 836
CoolGravatar
  • 5,408
  • 7
  • 35
  • 42

1 Answers1

1

Checkout the previous commit (state), C:

git checkout HEAD^

Don't worry about the "detached HEAD" message. Work work work, commit the changes needed to get E, then

git checkout -b branch-E

then branch-E contains E and its history. Now checkout the branch you were originally in to get to state D again.

I've shown it for getting to the previous commit, denoted HEAD^, but you can checkout any commit in your repo by giving its "treeish", e.g. its SHA1 value.

Fred Foo
  • 355,277
  • 75
  • 744
  • 836