teddy teddy
teddy teddy

Reputation: 3085

git blame on a line modified multiple times?

if a line is modified back and forth between 2 versions several times, git blame seems to show only the latest commits on that line.

would it be possible to let it show all commits on that line?

Upvotes: 17

Views: 5199

Answers (5)

Eric L.
Eric L.

Reputation: 31

Based on the answers already provided here, I created a script called git-rblame in my PATH with following content:

#!/bin/bash

revision="HEAD"

while [ -n "${revision}" ]
do
    result=$(git blame "${revision}" "$@")
    revision="${result%% *}"
    if [[ "${revision}" != [a-z0-9]*[a-z0-9] ]]
    then
        revision=""
    else
        echo "${result}"
        revision="${revision}~"
    fi
done

Then I can call git rblame -L xxx,yyy myfilename and I'll get the full history for the file respective the content given. Given the fact that the line number might change, a meaningful regexp seems to work better.

Upvotes: 0

Alexander Gladysh
Alexander Gladysh

Reputation: 41483

git blame can't do that itself (but see below for a workaround).

But git gui has a blame mode that allows you to drill down into commits.

Invoke it with git gui blame <filename> once installed.

Upvotes: 16

Matt Styles
Matt Styles

Reputation: 536

I don't know about showing all commits on that line at the same time, but you can "drill" through each change to the line by using git blame SHA~ -- filename. With each iteration of the blame, just insert the next most "recent" SHA which modified that line.

Example: The first time you run git blame foo.php you see the line was modified by f8e2e89a, so then you exit out and run git blame f8e2e89a~ -- foo.php, git will then show you who modified the line before f8e2e89a. Rinse and repeat as necessary.

Upvotes: 18

Todd A. Jacobs
Todd A. Jacobs

Reputation: 84443

You can't do what you want with git blame, but you might get close with a word-diff algorithm or some other custom diff tool. In particular, you could show a line-by-line word diff in your log output like so:

# Show deletions delimited with [- -], and additions with {+ +}.
git log --patch --word-diff=plain

See Also

Extract authorship information from git repository

Upvotes: 2

cdhowie
cdhowie

Reputation: 169403

The purpose of git blame is to show which commit most recently modified which lines in a particular file. It does not have an option to show multiple versions of the same line.

Upvotes: 0

Related Questions