Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git new branch then roll back to previous version

Tags:

git

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.

like image 611
Chapsterj Avatar asked Jan 25 '26 19:01

Chapsterj


1 Answers

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.

like image 125
three Avatar answered Jan 27 '26 09:01

three



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!