Case
Quite often I find myself staring at some old code that doesn’t look right. It looks like something has been removed (e.g. it has a loop that does nothing of value, or it creates a variable but doesn’t use it), or something is just hard to understand the point of. In these cases I would really need to see the history of that section of the file. Not all of the file though, just that section, or function.
Ideal solution
A simple command like
git log books.cpp:10
to find history of line 10 (possibly with surroundings) of file books.cpp is probably too much magic to ask for, but do you have ideas of how to work out that history?
What I have tried
I have tried using blame, and then checking out the commit before the given commit of that line – repeating it until I’ve seen enough. But that is very tedious work.
Have you felt the need for this feature? Do you have a way of achieving it? Share your experience!
Git is very easy to extend. Does something like this achieve what you want?
Put this little script in your path as something like
git-linehistoryand call it like this:It will show you what lines 5 to 15 look like at each commit for that file.