首頁·終端機命令

git log

git

用法

git log [--oneline] [--graph] [<range>] [-- <path>]

按從新到舊列出提交歷史,但只列目前 HEAD 的祖先,要看其他分支得加 --all。

常用選項

選項含義
--onelineone short line per commit
--graphdraw the branch lines
--allinclude every branch, not just the current one
-pshow the patch of each commit
--statshow which files changed
-n <n>stop after n commits
--since=<date>commits newer than a date, e.g. "2 weeks ago"
--followkeep following one file through renames

範例

git log --oneline --graph --all

the whole history as a compact graph

git log -p -- src/app.ts

every change ever made to one file

git log --since="2 weeks ago" --author=jade

recent commits by one person

難的地方在於復原有好幾種:把分支的指向挪走,和補一個反向提交,不是一回事。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. git log 是做什麼的?

按從新到舊列出提交歷史,但只列目前 HEAD 的祖先,要看其他分支得加 --all。

Q. 怎麼寫?

git log [--oneline] [--graph] [<range>] [-- <path>] —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 8 個,完整列表在 man git。這條命令屬於git。

相關命令

man 手冊: man git-log