git查看单个文件的所有修改记录
命令
点我打开git官网学习git的全部用法
git log --format="%h %an (%ad) : %s" --date=iso <文件路径>
%h
是提交哈希的缩写%an
是作者名字%ad
是作者日期%s
是提交主题--date=iso
日期格式化yyyy-MM-dd HH:mm:ss<文件路径>
相对于仓库的根路径。例如:src/pages/Bill/index.vue
1. 提交信息相关
占位符 | 说明 |
---|---|
%H | 完整的提交哈希(40字符) |
%h | 简短的提交哈希(7字符) |
%T | 完整的树对象哈希 |
%t | 简短的树对象哈希 |
%P | 完整的父提交哈希 |
%p | 简短的父提交哈希 |
%s | 提交标题(subject) |
%f | 提交标题(文件名形式,适合文件名) |
%b | 提交正文(body) |
%B | 原始提交信息(包括标题和正文) |
2. 作者和提交者信息
占位符 | 说明 |
---|---|
%an | 作者名字(Author Name) |
%ae | 作者邮箱(Author Email) |
%ad | 作者日期(Author Date,可用 --date= 格式化) |
%aD | 作者日期(RFC2822 格式) |
%ar | 作者日期(相对时间,如 “2 days ago”) |
%at | 作者日期(Unix 时间戳) |
%cn | 提交者名字(Committer Name) |
%ce | 提交者邮箱(Committer Email) |
%cd | 提交者日期(Committer Date) |
%cD | 提交者日期(RFC2822 格式) |
%cr | 提交者日期(相对时间) |
%ct | 提交者日期(Unix 时间戳) |
3. 引用和分支信息
占位符 | 说明 |
---|---|
%D | 引用名称(如 HEAD -> main, tag: v1.0 ) |
%S | 引用名称(不含 refs/heads/ 前缀) |
%d | 引用名称(装饰格式,如 (HEAD -> main) ) |
%gD | 引用名称(更详细的格式) |
4. 其他信息
占位符 | 说明 |
---|---|
%n | 换行符 |
%% | 百分号 % |
%Cred | 切换颜色为红色(需结合 %C() 使用) |
%Cgreen | 切换颜色为绿色 |
%Cblue | 切换颜色为蓝色 |
%Creset | 重置颜色 |
%C(...) | 自定义颜色(如 %C(auto) ) |
%G? | GPG 签名状态(G =有效,B =无效,U =未验证) |
%GS | GPG 签名者名字 |
5. 常用组合示例
(1)简洁格式(哈希 + 作者 + 日期 + 标题)
bash
git log --format="%h - %an (%ad) : %s"
输出示例:
text
abc1234 - John Doe (2023-10-01) : Fix login bug
(2)带颜色的输出
bash
git log --format="%C(yellow)%h%Creset - %C(blue)%an%Creset : %s"
https://i.imgur.com/XYZ123.png
(3)仅显示哈希和标题(适合脚本处理)
bash
git log --format="%H %s"
(4)自定义日期格式
bash
git log --format="%h %an (%ad) : %s" --date=short
或使用 ISO 格式:
bash
git log --format="%h %an (%ai) : %s"