how to checkout previous commit code example
Example 1: after checking out a previous commit go back to latest commit
git checkout <commit hash> # go to previous commit
git revert <commit hash> # revert action of going to previous commit
Example 2: git checkout commit
git checkout <commit>
Example 3: git checkout previous commit
git reset --hard HEAD~10
To rollback 10 commits back:
Example 4: checkout master with previous commit
git checkout 307a5cd # check out the commit that you want to reset to
git checkout -b fixy # create a branch named fixy to do the work
git merge -s ours master # merge master's history without changing any files
git checkout master # switch back to master
git merge fixy # and merge in the fixed branch
git push # done, no need to force push!
Example 5: git checkout previous commit
$ git reset --hard <commit_id>
Example 6: git checkout previous commit HEAD
git checkout <commit_id>
git checkout -b <new branch> <commit_id>
git checkout HEAD~X