Use case:
I find a piece of code that I do not understand at all. I want to find the temporal context in which this code was written, and all of the changes that this part of the code underwent.
Basically look up the history of this file but only the parts of that history which intersect with [lines 34 thru 38 (as an example)].
Is there a command for this that is more useable than git log -p <file> | grep <some snippet matching mysterious code> and then going back to the log -p output to look at the context in the diff there.
What’s sad is that I often find the need for this kind of functionality when reviewing code that I wrote.
git blame <path to file>will give you list of commits with context (changes done at at that commit point in that file). Readgit help blamefor all the powers it has.Then you can use
git show <commit>:<path>to see the whole file at that commit point orgit diff <commit> <commit> -- <path>to see the difference