git blame on a line modified multiple times?
Asked Answered
D

5

16

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?

Displant answered 14/6, 2012 at 6:19 Comment(1)
See #8435843. Its doable, and quite easy.Mordy
P
16

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.

Primipara answered 14/6, 2012 at 6:33 Comment(0)
S
17

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.

Sphenic answered 13/8, 2013 at 16:45 Comment(0)
P
16

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.

Primipara answered 14/6, 2012 at 6:33 Comment(0)
R
2

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

Rattlebrain answered 15/6, 2012 at 7:43 Comment(0)
M
0

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.

Modern answered 14/6, 2012 at 6:23 Comment(3)
thanks. unfortunately I was looking for something similar to the blame button of perforce , which shows you all commits in historyDisplant
You can kind of simulate that by doing git blame HEAD~n -- filename where n starts at 0 and increases. This isn't interactive, but each time you increment the number you'll be looking further back in history.Modern
hehehe . I used to do something similar in my svn days: perl -e 'for $v ( 0 .. $current_version ) { system(qq(svn diff -r).($v-1).qq( -r$v mysource.java ) } 'Displant
P
0

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.

Parthenia answered 9/5, 2017 at 7:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.