![]() ![]() 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 To do this, we pipe again but this time into sort: git log -pretty=oneline master.Why Git blame sucks for understanding WTF code (and what to use instead) | .uk .uk If the list is long, we probably want to sort it and remove any duplicates. We use the regex argument and have grep print out the matching text: git log -pretty=oneline v | grep -e '\+-\+' -o This output is easier to work with because we can pipe it into grep. Now we should be seeing something like this: 8e0e17 Update ProductController not to use param for is_mobileĭf6563 Rename SLICE_SIZE to CHARS_IN_PREVIEWS Instead, let’s make the output a bit shorter: git log -pretty=oneline v We’re programmers so we’re not doing that :) To get the issue numbers from this output, we’d have to manually cut and paste. However, this gives us a long format similiar to that one above. To this, we can compare the git logs between the two branches with this command: git log v It can be particular helpful, if you comparing between a master branch and a dev branch to discover which jira issues are resolved in dev but currently not in master. Update ProductController not to use param for is_mobileĬommit df6563d9f54ea11f04dbbf67f5c13642f7f77556 Many of my blog readers have discovered my article on how to add the Jira Issue Number to Git Commit Message and I continue to work with projects where we make use of the Atlassian toolchain, most prominently Jira for issue tracking and Confluence as a Wiki.Īssuming your commit log looks like this: commit 8e0e17e6150c757c5ed186413fd304940435ac6e TLDR git log -pretty=oneline master.your-branch | grep -e '\+-\+' -o | sort -u ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |