List all the versions of a given line number in the GIT history

git

Solution

This will call `git blame` for every meaningful revision to show line `$LINE` of file `$FILE`:

git log --format=format:%H $FILE | xargs -L 1 git blame $FILE -L $LINE,$LINE

As usual, the blame shows the revision number in the beginning of each line. You can append

| sort | uniq -c

to get aggregated results, something like a list of commits that changed this line. (Not quite, if code only has been moved around, this might show the same commit ID twice for different contents of the line. For a more detailed analysis you'd have to do a lagged comparison of the `git blame` results for adjacent commits. Anyone?)

Problem

Is it possible in Git to list all the previous versions of a given line in a file by the line number? The reason why I would find it useful is to be able to easier troubleshoot a problem based on logged stack trace report. i.e. I have a `undefined method exception` logged at a line 100 of a given file. The file is included in plenty of commits which caused the given line might have 'traveled' up and down the file even without any changes made to it. How would I print out the content of line 100 of a given file across last x commits?

Original source

Related problems