Git - 日志

记录常用的日志查询方式及格式

git log

bash 复制代码
commit <commitID>
Author: <user><<email>>
Date:   <time>

    <info>

    Change-Id: <changeID>

git log -p

bash 复制代码
# 在 git log 的基础上追加补丁信息
diff --git <file> <file>
index 54f466c..292b0df 100755
--- <file>
+++ <file>
@@ -252,7 +252,7 @@
         .............

git log --stat

bash 复制代码
# 在 git log 的基础上追加各个文件修改行信息
<file> | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

# 不携带具体文件信息
--shortstat
1 file changed, 1 insertion(+), 1 deletion(-)

git log --name-only

bash 复制代码
# 在 git log 的基础上追加修改的文件
<file>

# 携带文件修改状态
--name-status
M       <file>

git log --pretty=<>

bash 复制代码
oneline == git log --oneline, 只有 commit(短) msg
medium     默认
short      比默认少 Date 和 Change-Id, 即,只有 commit Author msg
full       比默认多 Commit Merge, 少 Date
fuller     比full多 AuthorDate CommitDate
email
  From <commitID> <time>
  From: <user> <<email>>
  Date: <time>
  Subject: [PATCH] <info>

  Change-Id: <changeID>
raw        比默认多 tree parent committer, 少 Date
format:
  %H  显示hash
  %h  提交对象的简短哈希字串
  %T  树对象(tree)的完整哈希字串
  %t  树对象的简短哈希字串
  %P  显示父节点hash
  %p  父对象的简短哈希字串
  %ad 显示作者时间 Mon May 15 09:40:07 2023 +0800
  %cd 显示提交时间 Mon May 15 09:40:07 2023 +0800
    --date=format:%Y-%m-%d %H:%M:%S 指定时间显示格式
  %ae 显示作者邮箱
  %ce 显示提交者邮箱
  %an 作者(author)的名字
  %cn 提交者(committer)的名字
  %ar 作者修订日期,按多久以前的方式显示
  %cr 提交日期,按多久以前的方式显示
  %s  显示主题
  %b  显示内容

git log --date=<>

bash 复制代码
relative == git log --relative-date
local       本地时间
iso         ISO 8601 format
rfc         RFC 2822 format
short       YYYY-MM-DD format
raw         %s %z format
format
  %a:星期缩写, Tue
  %A:星期全称, Tuesday
  %b:月份缩写, Jul
  %B:月份全称, July
  %c:时间全称, Tue 04 Jul 2023 02:24:58 PM GMT
  %d:日期 (01 -- 31), 04
  %H:小时 (00 -- 23), 14
  %I:小时 (01 -- 12), 02
  %j:一年中第几天 (001 -- 366), 185
  %m:月份 (01 -- 12), 07
  %M:分钟 (00 -- 59), 27
  %p:上午下午, AM/PM
  %S:秒数 (00 -- 59), 58
  %U:一年中的第几周,周日为一周的开始 (00 -- 53), 27
  %w:星期编号 (0 -- 6; 周日 is 0), 2
  %W:一年中的第几周,周以为一周的开始 (00 -- 53), 27
  %x:本时区的日期, 07/04/2023
  %X:本时区的时间, 02:24:58 PM
  %y:2位年份 (00 -- 99), 23
  %Y:4位年份, 2023
  %z, %Z:时区编号和时区名称缩写, +0000 GMT
  %%:Percent sign

其他参数

bash 复制代码
# 显示7位commit
--abbrev-commit

# 显示提交时间与当前时间差
--relative-date

# 显示 graph 信息
--graph

显示数量

bash 复制代码
-n          显示前n条
--after     在之后
--until     结束时间
--before    在之前
--since     开始时间
--author    作者
--grep      内容
--          文件
<br>        分支
--branches  所有分支,只是本地的所有分支
--no-merges 忽略合并的提交,两个分支合并代码时可能出现两个父节点的节点,该节点就是合并的提交,同理还有--merges参数
相关推荐
do better myself1 小时前
网站源码如何部署和加入GIT仓库的
git
爱学英语的程序员4 小时前
Git 提交 LF will be replaced by CRLF the next time Git touches it 报错
git
qq_339191144 小时前
服务器git pull每次都要输入密码,linux 设置git登录,linux设置git只输入一次账户密码
git
一颗小行星!10 小时前
快速理解 Git submodule
git
A-Jie-Y13 小时前
Git基础-核心概念与常用命令
git
夜珀13 小时前
Git基础修炼手册:在AtomGit上玩转版本控制
git
golang学习记13 小时前
Zed IDE官宣新招:Git Graph 正式支持!
ide·git
要记得喝水14 小时前
适用于 Git Bash 的脚本,批量提交和推送多个仓库的修改
git·elasticsearch·bash
AI_Claude_code14 小时前
专栏导论:开源项目贡献的价值与Git工作流全景图
git·开源
never forget shyang14 小时前
CCS20.2.0使用教程
c语言·git·单片机