What does the git log command do? By default, it shows you the log of commits starting from the latest commit of the branch you’re on. The first time I used git log was three or four years ago, I don’t actually remember why but probably to look up some stuff. Stuff that I guess I looked up scrolling over hundreds and hundreds of log entries for hours like a noob. Let me tell you about the first time I got more out of git-log.
Sun was shining hot, it was a Wednesday, probably in July. I got asked to investigate a bug that showed up in production around a feature I helped develop a couple of months prior that just went live for a few hours. After some intensive debugging I realized that the issue a missing null check which I was certain I wrote after running into a similar issue on my machine. Even crazier the unit test I remember adding alongside the code was not there either.
I remember my mind racing trying to retrace my every single move when writing the code. Did I forget to commit? Had I forgotten a push before opening my pull request? I knew exactly where to go: git log. A great plan, in theory, except I had to go back a couple of months on a repository where all the devs work on. The scroll was going to be a very long one.
That’s when I started looking for ways to filter the result of a git log. I found that post on StackOverflow post from 2011 indicating that you can filter git log by author. Only then did I go for the manual page of git-log to figure if more options were available. Eventually, that lead me to write something like that:
git log --since=YYYY-MM-DD --until=YYYY-MM-DD --author=CENSORED_OLD_WORK_EMAIL
That command allowed me to figure that the commit was in both our development and master branches. The only explanation is that someone reverted it. Had I been curious enough, I could have run git-log with the –grep option to find who reverted my commit but I had more pressing stuff to deal with. In order to play safe, I copy-pasted my reverted changes back into a hotfix branch which made it to production about an hour or two later through our release pipeline.
Obviously, don’t hesitate to check out the git log documentation for more info. Also, if you want more git stuff here, check out my epic cheat sheet of epicness git entry. I may reshape it at some point to make it more of a cheatsheet, basically a list of stuff without the stories that might become their own posts like this one, especially if that does well.
Cover by Oziel Gómez from Pexels