I created a new file (with quite a bit of code and hard work) and committed it to the master branch of my git repo. A moment later I realized that I probably should've created a branch for the file. I thought I could revoke the commit from master and commit again on a branch, but I think I did things in a silly order. For some reason I created the branch first, then went to revoke the commit, using is it possible to revoke commits? as a guide.
Here's essentially what I did:
echo "Lots of code and hard work" > newfile.txt
git commit -m "thoughtless commit" newfile.txt
# Oh wait, I should've branched!
git branch thoughtful
git checkout thoughtful
# Hmm, I didn't mean for that last commit to be in master
git checkout master
# get the previous commit's hash
oldhead=$(git log | awk 'BEGIN{commitcount=0; } /^commit/{ if (commitcount++ == 1) { print $2 }; }')
git reset --hard "$oldhead"
git checkout thoughtful
So now I've apparently trashed a commit on master (indeed, 'newfile.txt' no longer exists on master), but it still exists in thoughtful (and I guess reflog).
Would someone be so kind as to explain what I did here, and why no commit on thoughtful is required?