When coding, I often find myself wanting to quickly check the details of a function or method related to what I’m working on. For instance, I might need to understand how the function handles its arguments or recall its side effects.
I usually use ctags with Vim for this. A quick ], a brief read, and a <Ctrl-o> and I’m back from whence I came and more informed for my effort. Still, sometimes would be more convenient to just have the code printed right to my terminal from the command line.
If you’re here, you might remember that we previously looked at Git’s ability to walk the history of a specific method using git log -L1. What you might not know is that git log and git show are close siblings—actually defined in the same source file in the Git codebase. I tried pretty hard to find the right incantation to ask git-show to display just a specific function. I often use it to show a file at a given commit with git show some-branch:path/to/file to print a full file at a given commit. I was hopeful that it would have some variant to show what Git calls “hunks”, but despite learning that several Git builtins do indeed have some hidden flags, I just couldn’t make it work.
After that I spent way too long spelunking the Git codebase to try and retrieve the Regex pattern2. git config won’t give it to you unless it’s one you’ve defined in your own ~/.gitconfig. For my purposes that wasn’t useful as I let Git use it’s built-in Ruby patterns. I got as far as figuring out that passing git check-attr diff <filename> will give me the name of the diff Regex that it looks up the actual Regex if I’d defined it in ~/.gitattributes, which was nice to know but not useful.