to revert a commit without losing data in git code example Example: reset last commit without losing changes git reset HEAD~1 --soft