2/27/2024 0 Comments Git blame historyYou'll get an email whenever I have a fresh insight or tip to share. Want more juicy Git tips like this straight to your inbox? To learn more about the how and why of putting together more useful histories, check out A Branch in Time (a talk about revision histories). If the history hasn’t been constructed with atomic commits that have useful commit messages, searching it will likely be a frustrating and unhelpful experience. Of course searching a codebase’s history will only be fruitful if the history itself is helpful. Search commit messages using git log -grep.Search with a regular expression using git log -G.Scope search to specific folders or files by including a path.Include -reverse to see the commit that introduced the code listed first.Include -p to see the diff as well as the commit messages.Find the entire history of a snippet of code with git log -S.Next time some code has you puzzled and you want to understand more about it, look beyond git blame and dig deeper into the history using the pickaxe and friends: It lets you search for all commits that contain a given string: If git blame is entry-level history search, git log -S (also known as “the pickaxe”) is how you take things to the next level. Find all commits containing a particular piece code Let’s take a closer look at some of the tools at our disposal. Thankfully Git has some pretty powerful search tools built right in. Wouldn’t it be better to view things in 3D!? A more powerful way to trace the history of WTF code If you only use git blame you’re limiting yourself to a one-dimensional perspective of the code you’re trying to understand. The code you are interested in may also appear in other files, but to get the relevant commits on those you’ll need to run blame several times. git blame is too narrow: it only considers the file you are running blame against.The story of the particular piece of code you’re interested in may have evolved over several commits. git blame is too shallow: it only reports a single change the most recent one.If the most recent change isn’t related to the part of the line you’re interested, you’re out of luck. git blame is too coarse: it reports against the whole line.But often it isn’t and you’re none the wiser. After all, git blame gives you the commit that most recently touched the line, and often that’s enough to point you in the right direction. When this happens you might instinctively reach for git blame to help you figure out what’s going on. Or perhaps it’s doing something completely unsurprising, it’s just doing it in a surprising way. You’re happily working your way through a codebase when you happen upon some code that makes you stop and think: What the…!? Maybe it’s a method that’s doing something surprising. Why Git blame sucks for understanding WTF code (and what to use instead) November 13, 2020 Why Git blame sucks for understanding WTF code (and what to use instead) | .uk .uk
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |