Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to roll back to a previous commit without losing further ones?

Say, I want to roll back to a commit by git reset --hard <commit's ID> to see how the project’s structure looked like. But I don’t want to lose the commits that go after that one commit that I want to roll back to. I just want to roll it back if needed and see how everything looked and then go back to my latest commit.

How do I achieve this?

(I tried searching this up but didn’t find anything, all the resources were just about rolling back to the commit)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

  1. Find the hash or SHA for the commit you would like to go back to. This can be done using git log. The hash is the string of random characters that identifies that commit.
  2. Use git checkout <hash> to move to that commit
  3. When you are done looking around, move back to your latest commit and continue working as usual.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading