Retrieve Git history for a specific line in a file (Git)

With git blame you can view the last commit which changed any given line, but what if you want to see the history/activity of a specific line - why was it added, who changed it and when?

Git 1.8.4 introduced the ability to do this with git log, you just need to know the (current) line number

Details

  • Language: Git

Snippet

git log -L $lineno,$endlineno:$file

Usage Example

ben@milleniumfalcon:~/Documents/src.old/HLS-Stream-Creator$ git log -L 351,351:HLS-Stream-Creator.sh
commit db85e45814b2a163c5ae927bca36a74460483fe7
Author: B Tasker <github@mail>
Date:   Fri Jul 26 13:03:02 2019 +0100

    HLS-24 Allow audio track to be ignored with the `-n` commandline argument

    This forces `-an` to be passed to `ffmpeg`.

    It's not generally required, as missing audio tracks will be handled by default, but this allows the user to address inputs where `ffmpeg` reports the Audio type as `none`:

        Stream #0:0: Video: flv1, 1 reference frame, yuv420p, 1280x720, 199 kb/s, 8.33 tbr, 1k tbn, 1k tbc
        Stream #0:1: Audio: none, 0 channels

    This test stream was the result of a webcam being published into an RTMP relay with FFMPEG and then pulled back out the other side.

diff --git a/HLS-Stream-Creator.sh b/HLS-Stream-Creator.sh
--- a/HLS-Stream-Creator.sh
+++ b/HLS-Stream-Creator.sh
@@ -300,1 +302,1 @@
-while getopts "i:o:s:c:b:p:t:S:q:u:k:K:Clfe2" flag
+while getopts "i:o:s:c:b:p:t:S:q:u:k:K:Clfe2n" flag

commit bc201e0d5089166793646bdfa27d52be53c62d99
Author: JapSeyz <JapSeyz@mail>
Date:   Fri Oct 13 22:03:38 2017 +0300

    Added -u, -k and -K flags

diff --git a/HLS-Stream-Creator.sh b/HLS-Stream-Creator.sh
--- a/HLS-Stream-Creator.sh
+++ b/HLS-Stream-Creator.sh
@@ -269,1 +278,1 @@
-while getopts "i:o:s:c:b:p:t:S:q:Clfe2" flag
+while getopts "i:o:s:c:b:p:t:S:q:u:k:K:Clfe2" flag