git go back to previous commit without losing changes code example
Example 1: reset last commit without losing changes
git reset HEAD~1 --soft
Example 2: 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