Show HN: Git Searcher, search commits for an added or removed string (github.com)

3 points by seccode ↗ HN
Hello all,

I created a command line utility called Git Searcher that can find in which commit any line of code was added; it can also find where a line of code was removed. I have found this very helpful for determining where code originated from and for debugging. I hope you find this useful!

Many thanks, Sam

8 comments

[ 6.2 ms ] story [ 32.2 ms ] thread
The long term goal of this project is to integrate a "git search" command to git. I think this would be better than a standalone script
I personally do this by doing `jj log -pr ..` and then searching with my pager (/search expression).

My only nitpick with this is that it seems wrong to `git fetch` every time you want to search, but I think I understand why you did it.

Thanks for the feedback. Unfortunately `git fetch` is necessary to fetch any recent commits
It's your script and you should do what you want, but I definitely see that as a feature, not a bug. As a decentralized version control system, the repo on disk is your source of truth. In my mind, mutating your source of truth (such as via fetch) is and should be an independent operation from searching your source of truth.
How is this different from searching with "git log -G" or "git log -S"?

https://git-scm.com/docs/git-log#Documentation/git-log.txt--...

In making this, I found a bug in `git log -S` where it wasn't finding every instance of the search string. Perhaps a better way to further this project is to make a pull request into git to fix this, but I wasn't able to find the root cause of the bug
Also, git log shows where the string was both added and removed. If you only want to find either added or removed, this tool is better