[Practical Git] Filter commit history with git log arguments

In the last lesson, we learned how to format the git log output; in this lesson we will learn how to filter down to a specific set of commits. By default, git log shows every commit in a repo. We will walk through using a bunch of options to filter our git log commits to a more meaningful set (-n--after--before--author--grep-S-G--no-merges{ref}..{ref}{files}). We will also show how all of the formatting and filtering options can be composed together to query exactly what you are looking for in 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="10 minutes ago"
git log --after="2 weeks ago"
git log --after="3/15/16" // Match 15, 2016

 

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" -p // get all the commit which has Math.random changes in the code, and use -p option to see the code

Filter by the code using Regex:

git log -p -GMath\|random // 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"

git log --author="Jane" // search only for "Jane"

 

Filter out merges commit:

git log --no-merges

 

See the commits between two branch:

git log master..cool-feature

 

Search by files:

git log LIENCE.md README.md // search for lience and readme files

 

Example:

git log -3 README.md -p -i --author="Tavor" // Want to see last 3 change on README.md file by author Tavor, ignor the case, and show the code
git log -S"Math" --after="2 months ago" --oneline --stat

 

posted @   Zhentiw  阅读(243)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2014-08-11 [CSS] Collapsing Margins
2014-08-11 [Javascript] Ternary Conditionals
2014-08-11 [Javascript] Prototype, hasOwnProperty(), valueOf() and toString() methods.
点击右上角即可分享
微信分享提示