Search notes:

GIT: Inspect each version of a file

The Makefile for the Linux kernel defines 5 variables at the beginning: VERSION, PATCHLEVEL etc.
The following simple loop iterates over each version of the Makefile found in the git repository and uses git checkout combined with grep to extract the values of these variables.
The commit id and the values are then printed to stdout:
filename=Makefile

for commit in $(git log --pretty=format:%H -- $filename); do

    git checkout -q $commit $filename

    version=$(     grep -P -o '(?<=^VERSION = ).*'      $filename)
    patchlevel=$(  grep -P -o '(?<=^PATCHLEVEL = ).*'   $filename)
    sublevel=$(    grep -P -o '(?<=^SUBLEVEL = ).*'     $filename)
    extraversion=$(grep -P -o '(?<=^EXTRAVERSION = ).*' $filename)
    name=$(        grep -P -o '(?<=^NAME = ).*'         $filename)

    printf "%s %d.%02d.%d%-5s %s\n" $commit $version $patchlevel $sublevel "$extraversion" "$name"
done

# reset the file to its state in the current commit
git checkout HEAD $filename

Index