Skip to main content

Log

  • -p: 打印 diff 差异信息
  • -n: n 为十进制数字,显示最近 n 次信息
  • --stat: 打印简略统计信息
  • --graph: 显示分支合并历史
  • --pretty=: 设置日志格式
  • --author=: 指定作者
  • --committer=: 指定提交者
  • --after=/--since=: 限制日志时间
  • --before=/--until=: 限制日志时间 "2008-01-15" "2 years 1 day 3 minutes ago"
  • --decorate: 查看各个分支当前所指的对象(commit object)
  • --help
git log -p --stat --graph --pretty=format:"%h - %an, %ar : %s" --since=2.weeks path_name

Pretty Format

选项说明
%H提交对象(commit)的完整哈希字串
%h提交对象的简短哈希字串
%T树对象(tree)的完整哈希字串
%t树对象的简短哈希字串
%P父对象(parent)的完整哈希字串
%p父对象的简短哈希字串
%an作者(author)的名字
%ae作者的电子邮件地址
%ad作者修订日期 (可以用|-date=|选项定制格式)
%at作者修订日期 (ms)
%ar作者修订日期, 按多久以前的方式显示
%cn提交者(committer)的名字
%ce提交者的电子邮件地址
%cd提交日期
%cr提交日期,按多久以前的方式显示
%s提交说明

Options

选项说明
-p打印 diff 差异信息
-nn 为十进制数字,显示最近 n 次信息
--stat打印简略统计信息
--graph显示分支合并历史
--pretty=设置日志格式
--author=指定作者
--committer=指定提交者
--after=/--since=限制日志时间
--before=/--until=限制日志时间 "2008-01-15" "2 years 1 day 3 minutes ago"
--help

Filter

Amount

git log -3

Date

  • before and until
  • after and since
git log --before="yesterday"
git log --after="1 week ago"
git log --after="2014-7-1" --before="2014-7-4"

Author

git log --author="John\|Mary"

Commit Message

git log --grep="feat"
git log --grep="fix"

File

git log -- src/components/ErrorBoundary/ErrorBoundary.test.tsx
git log -- "*.test.tsx"

Content

git log -S"Hello, World!"

Range

git log main..feature

Reflog

分析你所有分支的头指针的日志来查找出你在重写历史上可能丢失的提交:

git reflog show is an alias for git log -g --abbrev-commit --pretty=oneline. git reflog is useful for trace local git manipulation history.

git reflog
git reset HEAD@{index}