小结一下 git log 命令的使用
git log 命令形式:
git log [<options>] [<since>..<until>] [[--] <path>...]
不带参时:
列出所有历史记录,最近的排在最上方
默认输出commit hash, author, date, commit message
记录过多时按Page Up、Page Down、↓、↑来控制显示
按q退出历史记录
带参时:
常用参数列举
参数 作用
-n 显示前n条
--stat 显示每次更新的修改文件的统计信息(列出修改过的文件+添加和移除行数+所有增减行数小计)
--stat -n 作用同上,显示前n条
--shortstat 显示--stat中最后的行数添加修改删除统计
-p 按补丁显示每个更新间的差异
--name-only 在已修改的提交信息后显示文件清单
--name-status 显示新增、修改和删除的文件清单
--abbrev-commit 显示SHA-1的前几个字符
--relative-date 以较短的相对时间显示(例:3 days ago)
--graph 显示ASCII图形表示的分支合并历史
--after= 显示日期/相对时间之后的日志
--before= 与上面相反
--author= 按作者显示
--oneline 每条日志的输出为一行
--pretty=raw 与上面相反(包含信息:提交ID,文件树ID,父提交ID,作者和提交者)
--format选项说明
参数 作用
%H 哈希值
%h 简短哈希值
%T tree哈希
%t tree简短哈希
%P 父哈希
%p 简短父哈希
%an 作者名
%ae 作者邮件
%ad 作者的日期
%ar 相对目前时间的作者日期
%cn 提交者名
%ce 提交者邮件
%cd 提交日期
%cr 相对目前时间的提交日期
%s 标题
git log --author='wangyanbao' --after="2022-05-01" --pretty=format:"%H %an %cd %s"
git cherry-pick 多个commit操作
经常需要从一个分支选择性的合并commit到另一个分支,具体可使用cherry-pick实现:
1.单个commit合并
git cherry-pick commit_id
1
2.多个连续commit合并
commit_id到commit_idn之间,包括两端
git cherry-pick commit_id..commit_idn
1
commit_id到commit_idn之间,非闭包
git cherry-pick (commit_id..commit_idn]
1
挑选多个commit:
git cherry-pick commit_id commit_idx commit_idy
1
3.合并过程中依次解决冲突后,继续合并
git cherry-pick --continue