Common Problems#
Undo unstaged local changes#
To overwrite local changes:
git checkout -- <file>
git reset --hard
Undo staged local changes#
To unstage the file but keep your changes:
git restore --staged <file>
git reset
git reset --hard
Undo committed local changes#
This is a always a bit harder... To undo last two commits, but keep your changes:
git reset HEAD~2
git reset --hard HEAD~2
Change commit#
To change the message of the last commit:
git commit --amend -m "New message"
git add forgotten_file
git commit --amend