When working on a project, sometimes you might discover an issue in your current commit that didn’t exist or didn’t appear in a previous commit. Here’s how you can get your code back to that working version:
NOTE: It is strongly recommended that you do this in a separate directory from the directory containing your code.
Find the commit hash you want to rollback to (e.g. aef557567um…) and copy it. It is usually 40 characters in length.
Clone your repository:
git clone https://nameofyourgitserver.com/username/reponame.git.
In the cloned repo’s directory type:
git checkoutfollowed by the commit hash from Step 1 that you want to rollback the repo to.
Your code should now be rolled back to the commit that you have chosen. You can keep repeating Step 3 as much as you want in order to get your code to any older or new commit in your repo.