git undo last commit local keep changes code example Example 1: undo last commit but keep changes git reset @~ Example 2: git revert commit but keep changes git reset HEAD^