> Oh shit, I accidentally committed something to master that should have been on a brand new branch!
# disappear the last commit and all changes from it
git reset --hard HEAD^
# make a new branch using the last commit
git checkout -b new-branch HEAD@{1}
> Oh shit, I accidentally committed to the wrong branch!first, you don't need to git-add before and after stash, stash will save the working directory and the index (as documented in the DESCRIPTION of git-stash(1)). but for a more logical way:
# disappear the last commit and all changes from it
git reset --hard HEAD^
# get onto the new branch
git checkout new-branch
# grab the stuff from what was on the old branch
git cherry-pick old-branch@{1}
> Oh shit, I tried to run a diff but nothing happened?! git diff --cached
recommended reading for intermediate git users: the DESCRIPTIONs of all of these commands (git-reset(1), git-checkout(1), git-cherry-pick(1), git-diff(1)), and the entirety of gitrevisions(7).