1. 83
    1. 21

      Related: In case you missed it (as I did up until a few days ago) the blame view on GitHub has an inconspicuous button next to each chunk that redoes the blame on the file prior to that particular change:


      It has made iterative blaming much faster for me.

      1. 16

        And if you want to do that locally, tig’s blame view supports that as well using ,.

    2. 11

      I use Emacs’ vc-annotate (C-x w g) to get the initial blame shown, and then I can inspect the commit log (l) and diff (=), and I can jump to the commit of the current line (j). To move to the previous commit (p) is then easy, making it possible to trace the history back, while showing log and diff when necessary, as I am jumping further back.

      1. 1

        I also like that a lot, but I’ve found it can’t cross merge commits (any commit with more than 1 parent). Is there a way around that?

    3. 8

      For archeology I really love git gui blame despite its dated UI. The “blame parent commit” feature is priceless. And it does a great job at tracking files across renames too

      I haven’t found an equivalent tool with a more modern UI yet

    4. 6

      I wish more tools would learn from other tools. I haven’t ever really seen Perforces Time-lapse view replicated many other places for example. It’s fantastic and I wish git tooling would evolve from it.


      1. 4

        Somebody did create one for git in Vim and I maintain a fork people might find useful - https://github.com/junkblocker/git-time-lapse

    5. 3

      Some of these are pretty useful. Especially “Find the commit that first added some code”. I always end up looking at git blame and most of the time the persons name on it just did some code reformatting or cleaning up trailing spaces. Then I have to look through the git log of the file anyways.

      Anyone out there use Tower or IntelliJ’s built in git tools? Do those app provide better visualizations for git blame?

      1. 2

        GitHub offers a way to iterate, see danburzo’s sibling comment.

      2. 1

        Something like

        Git blame commit^ — file

    6. 3

      One thing I’ve often wished for is the ability to git log method the way I can git log path. Show me all commits that modified within a method. Git clearly has this info since it shows up in @@ lines in diffs. Anybody know how to do this?

      1. 12

        You can totally do that! Try git log -L :<funcname>:<file>.

        You might need to give Git a hand recognising what’s a function depending on the language. Check https://tekin.co.uk/2020/10/better-git-diff-output-for-ruby-python-elixir-and-more to see how.

        1. 2

          git log -L :<funcname>:<file>

          Ooh! Thank you, this is a life-saver.

      2. 5

        My first impulse is git log -p, then / to search for patterns.

        The git-log man page includes:

        git log -L '/int main/',/^}/:main.c

        Shows how the function main() in the file main.c evolved over time.

        Edit: whoops, should’ve refreshed the page!

      3. 4

        Some commands, such as git blame and git log, that take the -L option also accept it in the form of a function name. The syntax for git log seems to be:

        git log -L “:funcname:file”

        1. 1

          git log -L :<funcname>:<file>

          Ooh! Thank you, this is a life-saver.

    7. 2

      I will add that files that are a complete chequerboard of commits by many different committers half of whom have left the company are very likely to be WTF code.

      And it’s unlikely that any single committer is “to blame”, rather shifting goal posts, too complex requirements, high staff turnover, and the code is probably far from SOLID.

    8. 2

      It’s a good trick, but the results might be overwhelmed by noise if the method name is insufficiently unique.

    9. 1

      Thanks this was really useful. I’ve reached for git blame a bunch of times and I don’t think I’ve ever actually found what I needed from it.