Skip to content

git 查看 ISO 格式的提交时间

1 min read
Terminal window
# command 1
git log -1 --date=iso-strict --format=%cd --date=unix <commit-hash> | xargs -I{} date -u -d @{} +"%Y-%m-%dT%H:%M:%SZ"
# command 2
git log -1 --format=%ct <commit-hash> | xargs -I{} date -u -d @{} +"%Y-%m-%dT%H:%M:%SZ"

也可以封装为一个 bash 脚本:

check-git-commit-time.sh
#!/usr/bin/env bash
# Save as check-git-commit-time.sh
# Usage: ./check-git-commit-time.sh <commit-hash>
if [ -z "$1" ]; then
echo "Usage: $0 <commit-hash>"
exit 1
fi
commit="$1"
# Get the commit's Unix timestamp
timestamp=$(git log -1 --format=%ct "$commit")
# Convert to UTC ISO 8601 format
date -u -d @"$timestamp" +"%Y-%m-%dT%H:%M:%SZ"
> reply via EMAIL

Comments