Command like grep -C 3 key file.txt
, can show 3 lines context around the matched line.
I'm wondering if git log can do the trick.
Asked
Active
Viewed 236 times
1

EricRen
- 7
- 2
-
1Does this answer your question? [List commits between 2 commit hashes in git](https://stackoverflow.com/questions/18679870/list-commits-between-2-commit-hashes-in-git) – 0stone0 Aug 05 '21 at 11:26
-
... Though that will still require some machinations to find the commit IDs of the surrounding commits. https://stackoverflow.com/questions/25664323/git-get-the-commit-hash-prior-to-a-specific-commit has some tips around that. – tripleee Aug 05 '21 at 11:27
-
Straight `git log` can't, but `git grep` can. Consider using that on each "interesting" commit. Since commits are snapshots, you may find too many matches this way; combine `git log` and `git grep` to trim these down. (Note that `git rev-list` is the plumbing variant of `git log`, at least for most cases, so it's usually the step you want instead of `git log` here.) – torek Aug 05 '21 at 12:36
-
hi @0stone0, thanks for the link, but it's not exactly what I dream. And thanks all the comments~ – EricRen Aug 06 '21 at 08:14