Search code examples
gitversion-control

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)


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.