Today I was resetting a local Git repository to previous commits,, in order to trace back some changes which lead to Continious Integration tests failures. I did a few trail and error runs with:
git reset --hard SHA
Where SHA was taken from GitHub or git log
. These commands were performed on my local branch which had some new changes commited locally, but not yet pushed to GitHub. Then, I found the working old commit I realized that I am stuck on it! There was a SHA for my latest commit and the command:
git log
wasn’t showing my latest commit either, because I moved the HEAD of the branch behind it. Thansk for an advice, this command saved me:
git reflog BRANCHNAME
It had a short SHA of my latest commit and I was able to reset HEAD back with reset
. I knew that Git had my change save, but I wasn’t sure how to get them. As usual Git is a great technology… with a terrible user interface! :-)
More on git reflog: