Question

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?

Était-ce utile?

La solution

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.

Autres conseils

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.

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.

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

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top