git-log

neevop 七月 2, 2023


提交日志

基本用法

# branch
git log master
# branch, remote
git log origin/master
# tag
git log v1.0.0

git log master develop
# reachable from master but not v2.0
git log v2.0..master
# reachable from master and v2.0, but not both
git log v2.0...master

基础过滤

-n, --max-count=2

    --skip=2
--since="1 week ago"
--until="yesterday"
--author="Rico"
--committer="Rico"

查询

# in commit message
--grep="Merge pull request"

# in code
-S console.log

# in code (regex)
-G "foo.*"

限制

--merges

--no-merges
# no stuff from merged branches
--first-parent
--branches="feature/*"
--tags="v*"
--remotes="origin"

简化

git log -- app/file.rb      # only file
  --simplify-by-decoration  # tags and branches

顺序

--date-order
--auther-date-order
--top-order
--reverse

格式化

--abbrev-commit
--online
--graph

格式

基本格式

--pretty="format:%H"

commit 哈希

Variable Description
%H commit hash
%h (abbrev) commit hash

Tree 哈希

Variable Description
%T tree hash
%t (abbrev) tree hash

parent 哈希

s

Variable Description
%P parent hash
%p (abbrev) parent hash

commit

Variable Description
%s commit subject
%f commit subject, filename style
%b commit body
%d ref name
%e encoding

auther and committer

Variable Description
%an auther name
%aN auther name, respecting mailmap

email

Variable Description
%ae auther email
%aE auto email, respecting mailmap

date

Variable Description
%aD auther date (rfc2882)
%ar auther date (relative)
%at auther date (unix timestamp)
%ai auther date (iso8601)

committer name

Variable Description
%cn committer name
%cN committer name, respecting mailmap

committer email

Variable Description
%ce committer email
%cE committer email, respecting mailmap

committer date

Variable Description
%cD committer date (rfc2882)
%cr committer date (relative)
%ct committer date (unix timestamp)
%ci committer date (iso8601)