Follow

git pro tip 

`git log -S some_variable_name` returns all commits where `some_variable_name` is in the diff (either removed, added, or modified)

super useful for tracking down regressions where you know the variable that's the culprit

git pro tip 

(of course it doesn't have to be a variable, this works for any string in the diff)

git pro tip 

@garbados that's what -S stands for

git pro tip 

@darius Yes! One of my faves, which means I've been bitten by an important nuance:

-S will not find diffs that only *modify* lines involving that variable, because it shows diffs that "change the number of occurrences of the specified string".

If you want to find those cases, you want `git log -G` instead, since it returns "differences whose patch text contains added/removed lines that match".

Heads up that -G takes a regex vs -S taking a substring (altho you can make -S regex with --pickaxe-regex). Fortunately they're right next to each other in `git help log`, which actually has a nice little example showing the difference between the two as well.

git pro tip 

@darius Oh nice. I've used `git bisect` a lot for tracking digressions, but that can be pretty heavyweight when you already have some idea of the issue.

git pro tip 

@darius sick! a good git log option i also am a big fan of is `git log -L`. you can add this flag and follow it with a function to list only that function's history, which is actually fairly practical in my workflow.

git pro tip 

@darius Do you mainly use git on the command line or do you use something like magit?

git pro tip 

@faebser Command line, myself. I don't know anything about the non-CLI ecosystem myself! I bet there's cool stuff out there.

Sign in to participate in the conversation
Friend Camp

Hometown is adapted from Mastodon, a decentralized social network with no ads, no corporate surveillance, and ethical design.