[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
时间: 2024-10-19 14:28:53

[Practical Git] Filter commit history with git log arguments的相关文章

[Practical Git] Format commit history with git log arguments

When running the git log command, we can pass in options as arguments toformat the data shown for each commit. In this lesson, we show how to use the oneline, decorate, graph, stat, and p options with git log. Show it oneline: git log --oneline git l

Git 撤销commit的注意事项

Git撤销commit的操作命令  git reset --hard HEAD^ 一.新建三个文件,demo1,demo2,demo3 二.git add 命令提交到暂存区,git reset HEAD demo1就是把提交到暂存区里的文件撤销. 上图中,执行git reset HEAD demo1就会把demo1从暂存区中撤销,现在是untracked. 三.git commit 提交本地仓库 上图中显示,git commit把demo2,demo3提交到本地仓库中. 四.现在想撤销之前的co

Git学习01 --git add, git commit , git log ,git status, git reset --hard, head

特点:Git极其强大的分支管理:分布式版本 集中式版本控制系统,版本库是集中存放在中央服务器的,而干活的时候,用的都是自己的电脑,所以要先从中央服务器取得最新的版本,然后开始干活,干完活了,再把自己的活推送给中央服务器.中央服务器就好比是一个图书馆,你要改一本书,必须先从图书馆借出来,然后回到家自己改,改完了,再放回图书馆.集中式版本控制系统最大的毛病就是必须联网才能工作. 使用Git 1.创建版本库 首先,选择一个合适的地方,创建一个空目录,通过git init命令把这个目录变成Git可以管理

[Git] Use git add --patch for better commit history and mitigating bugs

Let's split our changes into separate commits. We'll be able to check over our changes before staging them all from the terminal. Then, we'll see the positive effect it has on our commit history. git add --patch 1. Then in the cmd, we can type 's' st

Rewriting History with Git Rebase

http://code.tutsplus.com/tutorials/rewriting-history-with-git-rebase--cms-23191 1. Rebasing for a Linear HistoryThe first use case we'll explore involves a divergent project history. Consider a repository where your production branch has moved forwar

How to view file history in Git?

参考: http://stackoverflow.com/questions/1786027/how-to-view-file-history-in-git Use git log to view the commit history. Each commit has an associated revision specifier that is a hash key (e.g. 14b8d0982044b0c49f7a855e396206ee65c0e787 and b410ad4619d2

git使用总结(包含git commit message 和 changelog 工具的介绍)

[git的配置] 1.配置用户名和邮箱: 分为全局配置和局部配置 --system 系统配置  --global 全局配置    --local 局部配置 Git读取时:优先从local>global>system git config --global user.name name git config --global user.email email 2.别名的配置 使用git st 代替 git status git config --global alias.st status 配置

git撤销commit,但未git push的命令

在git push的时候,有时候我们会想办法撤销git commit的内容 1.找到之前提交的git commit的id git log 找到想要撤销的id 2.git reset –hard id 完成撤销,同时将代码恢复到前一commit_id 对应的版本 3.git reset id 完成Commit命令的撤销,但是不对代码修改进行撤销,可以直接通过git commit 重新提交对本地代码的修改--------------------- 作者:在路上的码农 来源:CSDN 原文:https

恢复git撤销commit的代码

使用git reset --hard 是将磁盘文件也删除 时候使用Git工作得小心翼翼,特别是涉及到一些高级操作,例如 reset, rebase 和 merge.甚至一些很小的操作,例如删除一个分支,我都担心数据丢失. 不 久之前,我在做一些大动作(rebasing)之前,我总是备份整个版本库,以防万一.直到最近我才发现git的历史记录是不可修改的,也就是说你不能更 改任何已经发生的事情.你做的任何操作都只是在原来的操作上修改.也就是说,即使你删除了一个分支,修改了一个提交,或者强制重置,你仍