Skip to content

git log 簡單說明

基本用法

git log
  • 列出 提交歷史,包括:

    • commit ID (唯一識別碼)
    • 作者 (user.name 和 user.email)
    • 提交時間
    • 提交訊息

常用參數

  • 顯示簡短的 log

    git log --oneline
    
    • 每個 commit 只顯示一行簡短的訊息(commit ID 簡短版本 + 提交訊息)。
  • 顯示圖像化的分支歷史

    git log --graph
    
    • 顯示 分支合併歷史走向 的圖像表示法。
  • 多個參數組合

    git log --oneline --graph --all
    
    • --all:顯示所有分支的 commit 歷史。
  • 篩選提交

    git log --author="你的名稱"
    git log --since="2024-01-01"
    git log --grep="修正"   # 搜尋提交訊息中包含「修正」的提交
    
  • 顯示檔案的修改歷史

    git log <檔案名稱>
    

快速示例

commit 9e1a4d3 (HEAD -> main)
Author: 使用者名稱 <email@example.com>
Date:   2025-02-17 14:20:05

    修正錯誤並優化程式碼

commit 8bce5f0
Author: 使用者名稱 <email@example.com>
Date:   2025-02-16 19:33:12

    新增功能 X

小提醒

  • git log 讓你掌握專案的歷史變更與每一次提交的細節,對於 除錯版本管理 都非常重要!
  • 搭配 --oneline 使用 可以讓歷史更簡潔易讀。