修改git log中的Date格式

本文介绍如何修改Git中查看日志的默认日期格式。通过使用`git config`命令,可以将日志中的日期格式调整为iso-strict-local格式,实现更清晰的时间显示。

默认的git log查看日志显示的格式如下:

Date:   Thu Aug 16 17:44:32 2020 +0800

//修改当前仓库log date格式
git config log.date iso-strict-local

 

//全局设置log date格式
git config --global log.date iso-strict-local
在 `git log` 中显示的时间是 **提交(commit)发生的时间戳**,默认情况下 Git 会记录两个时间: - **作者时间(author date)**:文件首次提交的时间。 - **提交者时间(committer date)**:最后一次提交修改的时间(例如通过 `git commit --amend` 或 `rebase` 等操作后更新的时间)。 --- ### ✅ 默认 `git log` 显示的时间 ```bash git log ``` 默认输出中会显示如下内容: ``` commit abcdef1234567890... Author: John Doe <john@example.com> Date: Mon Apr 5 12:34:56 2024 +0800 commit message ``` 这里的 `Date:` 字段显示的是 **提交者时间(committer date)**。 --- ### ✅ 显示作者时间和提交者时间 如果你需要同时看到 **作者时间和提交者时间**,可以使用以下命令: ```bash git log --pretty=fuller ``` 输出示例: ``` commit abcdef1234567890... Author: John Doe <john@example.com> AuthorDate: Mon Apr 5 12:00:00 2024 +0800 Commit: John Doe <john@example.com> CommitDate: Mon Apr 5 12:34:56 2024 +0800 commit message ``` - `AuthorDate`:作者第一次提交的时间。 - `CommitDate`:提交最终被写入的时间(例如 `--amend` 或 `rebase` 后的时间)。 --- ### ✅ 自定义 `git log` 时间格式 你可以使用 `--date` 参数自定义时间格式: ```bash git log --pretty=format:"%h %ad %s" --date=short ``` - `%ad`:作者时间 - `%cd`:提交者时间 - `--date=short` 支持的格式包括: | 格式名 | 示例 | |------------|--------------------------| | `relative` | 2 hours ago | | `local` | Mon Apr 5 12:34:56 2024 | | `iso` | 2024-04-05 12:34:56 | | `short` | 2024-04-05 | | `raw` | 1712296496 +0800 | --- ### ✅ 设置时区显示 Git 默认使用本地时区,也可以强制使用 UTC: ```bash git log --date=local git log --date=iso-local ``` --- ### ✅ 示例命令:显示简洁时间的提交历史 ```bash git log --pretty=format:"%h - %an, %cd : %s" --date=short ``` 输出示例: ``` abcde12 - John Doe, 2024-04-05 : Update README ``` ---
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值