【工具类】git log 常用别名,git log 干活,git log常用参数

git log 常用参数及 .gitconfig 配置

干货,执行下边命令,添加别名

  • 注意,需要将 knowledgebao 修改为自己的名字,根据自己需要添加,常用的别名有:st ll lg lga lgb
  • 执行下边语句,添加各种快捷键,执行 git lm, git lms, git ls, git lsm … 等试试效果吧
git config --global alias.co "checkout"
git config --global alias.ck "checkout --track -b" # checkout and tracked
git config --global alias.ci "commit"
git config --global alias.cl "clean -x -d -f"  # force clean and remove ignored files.
git config --global alias.st "status"
git config --global alias.sst "status --ignore-submodules=all"
git config --global alias.pl "pull"
git config --global alias.ps "push"
git config --global alias.lb "remote show origin"  # list branch
git config --global alias.li "status --short --porcelain --ignored"  # list ignored
git config --global alias.lo "ls-files -o '--exclude=build/*' '--exclude=.vscode/*'"  # list others
git config --global alias.cp "cherry-pick"
git config --global alias.ca "commit -a"
git config --global alias.br "branch"
git config --global alias.df "diff --ignore-cr-at-eol --ignore-space-at-eol"
git config --global alias.dc "diff --cached --ignore-cr-at-eol --ignore-space-at-eol"
git config --global alias.m "merge"
git config --global alias.dt "difftool"
git config --global alias.mt "mergetool"
git config --global alias.desc "describe --tags --long"

# 通过 git lm 查看自己的修改记录,关键字 --author --abbrev-commit
git config --global alias.lm "log --no-merges --color --author='knowledgebao' --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit"

# 通过 git lms 查看自己的修改记录, 同步显示被修改的文件,关键字 --stat --author --abbrev-commit
git config --global alias.lms "log --no-merges --color --stat --author='knowledgebao' --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit"

# 通过 git ls 查看所有的修改记录,关键字 --graph --abbrev-commit
git config --global alias.ls "log --no-merges --color --graph --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit"

# 通过 git lss 查看所有的修改记录,同步显示被修改的文件,关键字 --stat --graph --abbrev-commit
git config --global alias.lss "log --no-merges --color --stat --graph --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit"

# 通过 git ll  关键字 --first-parent
git config --global alias.ll "log --graph --oneline --abbrev-commit --decorate --first-parent --pretty='tformat:%ai %C(auto) %h %d %s %Cblue<%an %ar>'"

# 通过 git lg  关键字 --branches
git config --global alias.lg "log --graph --oneline --abbrev-commit --decorate --branches --pretty='format:%C(auto) %h %d %s %Cblue<%an %ar>'"

# 通过 git lga  关键字 --all
git config --global alias.lga "log --graph --oneline --abbrev-commit --decorate --all --pretty='format:%C(auto) %h %d %s %Cblue<%an %ar>'"

# 通过 git lgb  关键字 --all --simplify-by-decoration
git config --global alias.lgb "log --graph --oneline --abbrev-commit --decorate --all --simplify-by-decoration --pretty='format:%C(auto) %h %d %s %Cblue<%an %ar>'"

执行后 ~/gitconfig 文件内容增加了下边内容

[alias]
	co = checkout
	ck = checkout --track -b
	ci = commit
	cl = clean -x -d -f
	st = status
	sst = status --ignore-submodules=all
	pl = pull
	ps = push
	lb = remote show origin
	li = status --short --porcelain --ignored
	lo = ls-files -o '--exclude=build/*' '--exclude=.vscode/*'
	cp = cherry-pick
	ca = commit -a
	br = branch
	df = diff --ignore-cr-at-eol --ignore-space-at-eol
	dc = diff --cached --ignore-cr-at-eol --ignore-space-at-eol
	m = merge
	dt = difftool
	mt = mergetool
	desc = describe --tags --long
	lm = log --no-merges --color --author='knowledgebao' --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit
	lms = log --no-merges --color --stat --author='knowledgebao' --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit
	ls = log --no-merges --color --graph --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit
	lss = log --no-merges --color --stat --graph --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Cblue %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit
	ll = log --graph --oneline --abbrev-commit --decorate --first-parent --pretty='tformat:%ai %C(auto) %h %d %s %Cblue<%an %ar>'
	lg = log --graph --oneline --abbrev-commit --decorate --branches --pretty='format:%C(auto) %h %d %s %Cblue<%an %ar>'
	lga = log --graph --oneline --abbrev-commit --decorate --all --pretty='format:%C(auto) %h %d %s %Cblue<%an %ar>'
	lgb = log --graph --oneline --abbrev-commit --decorate --all --simplify-by-decoration --pretty='format:%C(auto) %h %d %s %Cblue<%an %ar>'

git log 参数

git log --help 查看,1700多行帮助

       --follow
       --no-decorate, --decorate[=short|full|auto|no]
       --decorate-refs=<pattern>, --decorate-refs-exclude=<pattern>
       --source
       --[no-]use-mailmap
       --full-diff
       --log-size
           --summary, --name-only, --name-status, --check) are not currently implemented.
       --grep=<pattern> further limits to commits whose log message has a line that matches <pattern>), unless otherwise noted.
       --skip=<number>
       --since=<date>, --after=<date>
       --until=<date>, --before=<date>
       --author=<pattern>, --committer=<pattern>
           --author=<pattern>, commits whose author matches any of the given patterns are chosen (similarly for multiple --committer=<pattern>).
       --grep-reflog=<pattern>
       --grep=<pattern>
           --grep=<pattern>, commits whose message matches any of the given patterns are chosen (but see --all-match).
       --all-match
       --invert-grep
       --basic-regexp
       --remove-empty
       --merges
       --no-merges
       --min-parents=<number>, --max-parents=<number>, --no-min-parents, --no-max-parents
           --min-parents=2 is the same as --merges.  --max-parents=0 gives all root commits and --min-parents=3 all octopus merges.
           --no-min-parents and --no-max-parents reset these limits (to no limit) again. Equivalent forms are --min-parents=0 (any commit has 0 or more
       --first-parent
       --not
       --all
       --branches[=<pattern>]
       --tags[=<pattern>]
       --remotes[=<pattern>]
       --glob=<glob-pattern>
       --exclude=<glob-pattern>
       --reflog
       --alternate-refs
       --single-worktree
       --ignore-missing
       --bisect
       --stdin
       --cherry-mark
       --cherry-pick
       --left-only, --right-only
       --cherry
       --merge
       --boundary
       --simplify-by-decoration
       --full-history
       --dense
       --sparse
       --simplify-merges
       --ancestry-path
       --full-history without parent rewriting
       --full-history with parent rewriting
       --dense
       --sparse
       --simplify-merges
       --ancestry-path
       --date-order
       --author-date-order
       --topo-order
                   ---1----2----4----7
       --reverse
       --no-walk[=(sorted|unsorted)]
       --do-walk
       --pretty[=<format>], --format=<format>
           --pretty=tformat:<format> were given.
       --abbrev-commit
       --no-abbrev-commit
       --oneline
       --encoding=<encoding>
       --expand-tabs=<n>, --expand-tabs, --no-expand-tabs
           --expand-tabs=0, which disables tab expansion.
       --notes[=<ref>]
       --no-notes
       --show-notes[=<ref>], --[no-]standard-notes
       --show-signature
       --relative-date
       --date=<format>
           --date=relative shows dates relative to the current time, e.g. “2 hours ago”. The -local option has no effect for --date=relative.
           --date=local is an alias for --date=default-local.
           --date=iso (or --date=iso8601) shows timestamps in a ISO 8601-like format. The differences to the strict ISO 8601 format are:
           --date=iso-strict (or --date=iso8601-strict) shows timestamps in strict ISO 8601 format.
           --date=rfc (or --date=rfc2822) shows timestamps in RFC 2822 format, often found in email messages.
           --date=short shows only the date, but not the time, in YYYY-MM-DD format.
           --date=raw shows the date as seconds since the epoch (1970-01-01 00:00:00 UTC), followed by a space, and then the timezone as an offset from
           --date=human shows the timezone if the timezone does not match the current time-zone, and doesn’t print the whole date if that matches (ie
           --date=unix shows the date as a Unix epoch timestamp (seconds since 1970). As with --raw, this is always in UTC and therefore -local has no
           --date=format:...  feeds the format ...  to your system strftime, except for %z and %Z, which are handled internally. Use --date=format:%c to
           --date=default is the default format, and is similar to --date=rfc2822, with a few exceptions:
       --parents
       --children
       --left-right
       --graph
       --show-linear-break[=<barrier>]
       --cc
       --combined-all-paths
           --cc are specified, and is likely only useful if filename changes are detected (i.e. when either rename or copy detection have been
           --raw. To get full object names in a raw diff format, use --no-abbrev.
       --output=<file>
       --output-indicator-new=<char>, --output-indicator-old=<char>, --output-indicator-context=<char>
       --raw
       --patch-with-raw
       --indent-heuristic
       --no-indent-heuristic
       --minimal
       --patience
       --histogram
       --anchored=<text>
       --diff-algorithm={patience|minimal|histogram|myers}
           --diff-algorithm=default option.
       --stat[=<width>[,<name-width>[,<count>]]]
           --stat-graph-width=<width> (affects all commands generating a stat graph) or by setting diff.statGraphWidth=<width> (does not affect git
       --compact-summary
       --numstat
       --shortstat
       --cumulative
       --dirstat-by-file[=<param1,param2>...]
       --summary
       --patch-with-stat
       --name-only
       --name-status
       --submodule[=<format>]
       --color[=<when>]
       --no-color
       --color-moved[=<mode>]
       --no-color-moved
       --color-moved-ws=<modes>
       --no-color-moved-ws
           --color-moved-ws=no.
       --word-diff[=<mode>]
       --word-diff-regex=<regex>
       --color-words[=<regex>]
       --no-renames
       --[no-]rename-empty
       --check
       --ws-error-highlight=<kind>
       --full-index
       --binary
       --abbrev[=<n>]
       --find-copies-harder
       --diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
       --find-object=<object-id>
       --pickaxe-all
       --pickaxe-regex
       --relative[=<path>]
       --ignore-cr-at-eol
       --ignore-space-at-eol
       --ignore-blank-lines
       --inter-hunk-context=<lines>
       --ext-diff
       --no-ext-diff
       --textconv, --no-textconv
       --ignore-submodules[=<when>]
       --src-prefix=<prefix>
       --dst-prefix=<prefix>
       --no-prefix
       --line-prefix=<prefix>
       --ita-invisible-in-index
           --ita-visible-in-index. Both options are experimental and could be removed in future.
           --- a/describe.c
               --- a/file
               --- a/file
               --- a/file
               --- a/file
           --notes=<ref> option.

–abbrev-commit 仅显示 SHA-1 的前几个字符,而非所有的 40 个字符。
–stat 显示每次更新的文件修改统计信息
–graph 显示 ASCII 图形表示的分支合并历史。
–no-merges 没有合并的提交信息
–color
–oneline --pretty=oneline --abbrev-commit 合用的简写。
–decorate 参数用来显示一些相关的信息,如HEAD、分支名、tag名等
–first-parent 紧当前分支的父分支
–author=‘xxx’ 提交至,使用单引号
–date=format:‘%Y-%m-%d %H:%M:%S’ 时间格式

–pretty 使用其他格式显示历史提交信息。可用的选项包括 oneline,short,full,fuller 和 format(后跟指定格式)
–pretty=format:‘%C(red)%h%Creset -%C(yellow)%d%C(blue) %s %C(green)(%cd) %C(bold blue)<%an>%C(reset)’
–pretty=format:‘%C(auto) %h %d %s %C(blue)<%an %ar>’
–pretty=format:‘%ai %C(auto) %h %d %s %C(blue)<%an %ar>’

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

参考资料

  • 6
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值