In the last lesson, we learned how to format the git log output; In this lesson we'll learn how to filter down to a specific set of commits. By default, git log
shows every commits in a repo. We'll walk through using a bunch of options to the filter our Git log commits to a more meaningful set (,,, -n
--after
--before
--author
, --grep
, -S
, -G
, --no-merges
, {ref}..{ref}
, {files}
). We'll also show how all of the formatting and filtering options can is composed together to query exactly what is L Ooking for with your commit history.
Show Lasat N Commit:
Git log-3// Show last three commit
Show commits from a center time:
git log--after="yesterday"//Show the commit between yesterday and today
git log--after="minutes ago"--after="2 weeks ago" --after="3/15/16"// Match.
Combine with--before:
git log--after="3/15/16" --before="yesterday"
The same as:
git log--since="3/15/16" --until="yesterday"
Filter by Author:
git log--author="tavor"
Filter by the commit message:
git log--grep="copyright"
Filter by the code using string:
git log-s"math.random"// get all the commit which have math.random changes in the Code, and Use-p option to see the code
Filter by the code using Regex:
// Using ' G ' without quotes and follow with regex math or random
Ingore the case:
git log-i--author="Jane"// search both for "Jane" and "Jane"-- author="Jane"// search only for "Jane"
Filter out Merges commit:
git log--no-merges
See the commits between-branch:
git log master. Cool-feature
Search by files:
// Search for Lience and Readme files
Example:
Git log-3 readme.md-p-i--author="tavor"// want to sees last 3 change o n readme.md file by author Tavor, ignor the case, and show the code
git log-s"Math" --after="2 months ago" --oneline-- Stat
[Practical git] Filter commit history with Git log arguments