Chapsterj
Chapsterj

Reputation: 6625

Git new branch then roll back to previous version

I have a few different branches including my master branch. I want to create a new branch from master which I think can be done like this correct me if I'm wrong.

git branch masterDup
git checkout masterDup

I then want to roll the masterDup branch back to an old version. Can this be done without effecting the master or any other branches. So only masterDup would be rolled back. If so how would I roll back using the commit ID just for this newly created branch.

I have the commit ID in the my log history. commit 6f041c1e37bb97aab35678d35c8923fabe33c8d2c

I'm using terminal for my git commands.

Upvotes: 3

Views: 1183

Answers (2)

three
three

Reputation: 8478

Sure, you check out a new branch with

git checkout -b masterDup

and then you reset it to an earlier version

git reset --hard HEAD~x 

where x is x versions back (or use the hash if you like)

edited this answer, see comments.

Upvotes: 2

Mario F
Mario F

Reputation: 47279

Right after the checkout of the new branch

git reset --hard 6f041c1e37bb97aab35678d35c8923fabe33c8d2c

Upvotes: 0

Related Questions