I am searching for something like git blame but instead of showing the commit the line was last changed in, I am interested in what version this line was committed.
So instead of the revision ID, I need the most recent tag at the time of the commit.
You can use the command
or in long form
This command replaces the first column in the git-blame output with the output of
git describe --always --tags --abbrev=0 <rev>. The first column will contain one of two possible values:If you want to pad/truncate the first column to have a fixed number of characters, you can use
which adds
| xargs -0 printf %10s | head -c10"to marshal the first column to have exactly 10 characters. Replace both instances of10with your desired width.Here's an example of the output using the README file from CPython:
Some additional implementation notes
--alwaysis needed in thegit describeinvocation to output the commit ID when no tag can be found.--abbrev=0is needed in thegit describeinvocation to only output the closest tag.--tagsin thegit describeinvocation enables both lightweight and annotated tags.git blameis processed throughtr -d "^"to remove the^prefix present when the line was last modified in the root commit.