跳到主要内容

1 篇博文 含有标签「Git」

查看所有标签

Git 常用命令

· 阅读需 2 分钟

git log

--since 语法

  1. 绝对日期格式
    • YYYY-MM-DD
    • Month Day, Year
    • YYYY-MM-DD HH:mm:ss
  2. 相对时间格式
    • N year/months/weeks/days/hours/minutes/seconds ago
    • yesterday/today
  3. --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" 格式化输出

  • %h commit hash
  • %an author name
  • %ad author date(format respects --date=option) 搭配 --date 使用--date=format:"%Y-%m-%d %H:%M:%S"
  • %ar author date, relative (相对时间)
  • %at author date, UNIX timestamp
  • %ai author date, ISO 8601
  • %ae author email
  • %s subject

查询指定日期之后提交记录并格式化显示

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 方式来合并远程代码