Update Git 2.18 (Q2 2018): "git blame
" learns to unhighlight uninteresting metadata from the originating commit on lines that are the same as the previous one, and also paint lines in different colors depending on the age of
the commit.
See commit 0dc95a4, commit 25d5f52, commit cdc2d5f (24 Apr 2018) by Stefan Beller (stefanbeller
).
(Merged by Junio C Hamano -- gitster
-- in commit 3d24129, 30 May 2018)
builtin/blame
: add new coloring scheme config
Add a config option that allows selecting the default color scheme for
blame. The command line still takes precedence over the configuration.
git config
now reports:
blame.coloring::
This determines the coloring scheme to be applied to blame output.
It can be 'repeatedLines
', 'highlightRecent
', or 'none
' which is the default.
builtin/blame: highlight recently changed lines
Choose a different color for dates and imitate a 'temperature cool down'
depending upon age.
Similarly to the previous patch, this offers the command line option
'--color-by-age
' to enable this mode and the config option
'color.blame.highlightrecent
' to select colors.
The documentation now adds:
color.blame.highlightRecent
This can be used to color the metadata of a blame line depending on age of the line.
This setting should be set to a comma-separated list of color and date settings, starting and ending with a color, the dates should be set from oldest to newest.
The metadata will be colored given the colors if the the line was introduced
before the given timestamp, overwriting older timestamped colors.
Instead of an absolute timestamp relative timestamps work as well, e.g.
2.weeks.ago is valid to address anything older than 2 weeks.
It defaults to 'blue,12 month ago,white,1 month ago,red
', which colors
everything older than one year blue, recent changes between one month and
one year old are kept white, and lines introduced within the last month are
colored red.
builtin/blame
: dim uninteresting metadata lines
When using git-blame
, lots of lines contain redundant information, for
example in hunks that consist of multiple lines, the metadata (commit
name, author, date) are repeated.
A reader may not be interested in those, so offer an option to color the information that is repeated from the previous line differently.
Traditionally, we use CYAN for lines that are less interesting than others (e.g. hunk header), so go with that.
The command line option '--color-lines
' will trigger the coloring of
repeated lines, and the config option 'color.blame.colorLines
' is
provided to select the color.
Setting the config option doesn't imply that repeated lines are colored.
Note: The "--color-lines
" and "--color-by-age
" options of "git blame
"(man) have been missing, which are now documented with Git 2.34 (Q4 2021).
See commit 8c32856 (08 Oct 2021), and commit 38c356a (01 Oct 2021) by Bagas Sanjaya (bagasme
).
(Merged by Junio C Hamano -- gitster
-- in commit 871e42e, 18 Oct 2021)
blame
: document --color-* options
Co-authored-by: Dr. Matthias St. Pierre
Signed-off-by: Dr. Matthias St. Pierre
Signed-off-by: Bagas Sanjaya
Commit cdc2d5f ("builtin/blame
: dim uninteresting metadata lines", 2018-04-23, Git v2.18.0-rc0 -- merge listed in batch #7) and 25d5f52 ("builtin/blame
: highlight recently changed lines", 2018-04-23, Git v2.18.0-rc0 -- merge listed in batch #7) introduce --color-lines
and --color-by-age
options to git blame
(man), respectively.
While both options are mentioned in usage help, they aren't documented in git-blame(1)
.
Document them.
git blame
now includes in its man page:
[--color-lines] [--color-by-age] [--progress] [--abbrev=]
[ | --contents | --reverse ..] [--]
blame-options
now includes in its man page:
--color-lines
Color line annotations in the default format differently if they come from
the same commit as the preceding line. This makes it easier to distinguish
code blocks introduced by different commits. The color defaults to cyan and
can be adjusted using the color.blame.repeatedLines
config option.
--color-by-age
Color line annotations depending on the age of the line in the default format.
The color.blame.highlightRecent
config option controls what color is used for
each range of age.
git config
now includes in its man page:
This setting should be set to a comma-separated list of color and
date settings, starting and ending with a color, the dates should be
set from oldest to newest. The metadata will be colored with the
specified colors if the line was introduced before the given
timestamp, overwriting older timestamped colors.
git config
now includes in its man page:
It defaults to blue,12 month ago,white,1 month ago,red
, which
colors everything older than one year blue, recent changes between
one month and one year old are kept white, and lines introduced
within the last month are colored red.
git config
now includes in its man page:
Use the specified color to colorize line annotations for
git blame --color-lines
, if they come from the same commit as the
preceding line. Defaults to cyan.
Original answer 2010
Considering web interface like Trac or Redmine integrate git blame
results, I suppose such a parsing has already been done.
You can see in this Redmine Defect 3832 an example with this ruby script: