Git Fishing
Let's go fishing with git! 🎣
Background: I work on a team that supports a large, globally available video game. We are in the middle of implementing a set of features and there was a misunderstanding of where the data is to be saved in a database table for the user generated data service, but we have the exact code we are looking for in our git log
I want to find the code that I wrote before so I don't have to think about how to do the task again because we spent that thought time already (Grug brain dev). my problem is I do not know the hash of what commit the code is in.
- I know git and grep and some basic Unix, so let's see what we can do
git log
lets me see all of the logs, so that's useful.grep -e 'pattern'
helps search for text- git log
-p
changes the output to the content of the commit - the
|
character takes output from command and pipes it into another command
git log -p | grep -e 'FirstPublishedDate'
will get me closer but the output is rather noisy; the word 'FirstPublishedDate'
is a common term in this development. Additionally, the output from grep is only structured by if a line contains that phrase; it's a bit of a salad without the context of git. so let's try again:
git log
has-G
to do a search, and I can narrow it by the branch namegit log -G'FirstPublishedDate' -p 143495-back-populate-new-filter-values
will narrow the search to the branch and do the filtering by pattern for me, and then-p
will show me the content- now let's use
grep -C 10
to show the ten lines around it, and use a new keyword like@@
to hone in on the hash.
our answer is git log -G'FirstPublishedDate' -p 143495-back-populate-new-filter-values | grep -C 10 -e '@@'
with the result
commit 530959f82def537a7f5a764b394dab1b4f3db77c
Author: Michael Gardner
Date: Mon Feb 5 16:17:36 2024 -0500
removed unused function
Right at the top. A not so unused function after all 🎣
© Michael Gardner IIRSS