git tricks

Author: yifei / Created: June 5, 2017, 6:30 p.m. / Modified: June 5, 2017, 6:31 p.m. / Edit

undo last commit

undo last commit when haven't pushed: git reset HEAD~

reset HEAD to origin

first, save your current work to another branch

git commit -a -m "Saving my work, just in case"
git branch my-saved-work

then, reset master branch to remote

git fetch origin
git reset --hard origin/master

undo last amend

git reset --soft HEAD@{1}