Git Reflog to the Rescue

Posted on Feb 10, 2021

I am an old Vim user and I’ve settled on Neovim as my editor of choice. I am running its v0.5.x because it offers LSP that I am using for Rust.

For that to work I am building the editor from the source. I am not, however, living on the bleeding edge and recompiling it every day for every small update. I tend to build it and then forget about updates for a month or two.

I’ve built it earlier today and immediately after noticed that something is not right. I was not able to paste anything because when I’ve pressed the middle mouse button the nvim could not leave insert mode. I have not had enough time to dive into and try to fix it so I’ve decided to revert but.. how do you do it for a software installed with make install?

Luckily for me, I’ve built it from the source meaning I had the repository cloned. Sadly, I did not know what was the old revision that worked for me. I could have just go back in time hoping that I would be lucky but there was a better way - git reflog.

The reflog is a record of every event that happens in the local repository. Whether a commit is made or changes are pulled - all is there. Even if a commit is removed it is possible to peel it out - pretty awesome and in some situations a life savior.

My reflog looked like that:

➜  neovim git:(master): git reflog
38ea2ce34 (origin/master, origin/HEAD, master) HEAD@{1}: pull: Fast-forward
e3afb30e6 (HEAD) HEAD@{2}: pull: Fast-forward
4ed5204bc HEAD@{3}: checkout: moving from b99dad7b4c6418978a21977262809021fab8d356 to master
b99dad7b4 (tag: v0.4.3, tag: stable) HEAD@{4}: checkout: moving from master to v0.4.3
4ed5204bc HEAD@{5}: clone: from

The first column is the git hash of the outcome of each action. For example, the HEAD was at e3afb30e6 after pulling changes for the 1st time and at 38ea2ce34 after I did it today.

There is no date but it is easy to figure out which one I need to go back to. After a short while needed for the build to complete I got my working nvim back and could continue my work without being annoyed at my editor.