Git 常用命令
· 阅读需 2 分钟
git log
--since 语法
- 绝对日期格式
YYYY-MM-DDMonth Day, YearYYYY-MM-DD HH:mm:ss
- 相对时间格式
N year/months/weeks/days/hours/minutes/seconds agoyesterday/today
--until--before结合--since即>=--until, 即<
从今天开始,过去 1 个月的提交
git log --since="1 month ago"
一行显示
git log --since="2025-06-01" --until="2025-07-01" --oneline
自定义输出
# %h commit hash 的缩写
# %an 作者
# %ar 提交的相对时间
# %s 提交信息
git log --since="1 month ago" --pretty=format:"%h - %an, %ar : %s"
图形化显示
git log --since="1 month ago" --graph --oneline
--pretty=format
--pretty:format"- %s" 格式化输出
%hcommit hash%anauthor name%adauthor date(format respects --date=option) 搭配 --date 使用,--date=format:"%Y-%m-%d %H:%M:%S"%arauthor date, relative (相对时间)%atauthor date, UNIX timestamp%aiauthor date, ISO 8601%aeauthor email%ssubject
查询指定日期之后提交记录并格式化显示
git log --since="2025-11-31" --author="wangzhy" --pretty=format:" - %s %ad" --date=format:"%Y-%m-%d %H:%M:%S"
git config
pull.rebase
git pull 命令的行为方式。
git config pull.rebase true表示使用 rebase 方式来合并远程代码 (要求有干净的工作区,即没有未提交的代码)git config pull.rebase false表示使用 merge 方式来合并远程代码