by billpg · 4y ago · 0 comments
Why? I recently configured my github to use a hidden email address. To this end, it required me to use a github.com email address it generated for my commits. I set it up and started pushing commits, everyone was happy.
Then I went to a different folder that had a separate clone of the same repo, and I forgot I had configured github this way. I made some changes and did the usual commit-and-push but github rejected it. I had used the wrong email. Oops.
But now I had a problem. My local repo had the commit with the wrong email address in place and I didn't know to change it. I couldn't make a new commit with the new email as the old one was still there. I looked up how to revert already committed commits and long story short I did it wrong and deleted all my recent changes.
Next time, if you want to reset the latest commit to an unstaged state:
git reset HEAD~
But regarding "deleting all my recent changes", another command I'd like to introduce you to is; git reflog
It shows you all of your commits that changed the tip (HEAD). Chances are your changes could be found there.I don't blame you for not knowing this. I learned by trial and error and most importantly, good colleagues who showed me the way.
edit: Typo/grammar