nurabha
nurabha

Reputation: 1222

How to go to a previous commit without deleting recent commits

Assume that I have made following commits: c1, c2, c3 and that I am presently on commit c3. Now I want to go back to commit c1 without removing c2 and c3 commits. Once I am on c1, I want to create another branch from there. How do I do it ?

Upvotes: 0

Views: 270

Answers (1)

fge
fge

Reputation: 121840

Just create the branch directly:

git branch newbranch commitid

And commitid can be a lot of things. HEAD~2 will do what you want for your specific example.

And by the way, you wouldn't even lose c2 and c3 if you just checked out c1: they are available in the reflog (see git reflog).

Upvotes: 3

Related Questions