问题
I would like to use git log (open to other suggestions) to list all commits that either
- Were done by a specific author
or
- Which have a specific word in their commit message
I know how to search for each separately, but I would like a single list containing all matching commits. What is the easiest way to achieve this?
回答1:
You can use git rev-list
to generate the hash IDs that git log
should show, and then use git log --no-walk --stdin
to read those IDs, sort them according to the usual git log
sorting criteria, and show them. (Note: This will occasionally change the output order from what you would see with git log
without --no-walk
.)
For instance:
(git rev-list --author 'A. U. Thor' HEAD;
git rev-list --grep 'pattern' HEAD) |
git log --no-walk --stdin
(split into three lines for posting purposes; some command line interpreters will require that the command be a single line when actually used).
来源:https://stackoverflow.com/questions/48215421/git-log-to-show-commits-either-by-author-or-commit-message