git log
git
用法
git log [--oneline] [--graph] [<range>] [-- <path>]按從新到舊列出提交歷史,但只列目前 HEAD 的祖先,要看其他分支得加 --all。
常用選項
| 選項 | 含義 |
|---|---|
| --oneline | one short line per commit |
| --graph | draw the branch lines |
| --all | include every branch, not just the current one |
| -p | show the patch of each commit |
| --stat | show which files changed |
| -n <n> | stop after n commits |
| --since=<date> | commits newer than a date, e.g. "2 weeks ago" |
| --follow | keep following one file through renames |
範例
git log --oneline --graph --allthe whole history as a compact graph
git log -p -- src/app.tsevery change ever made to one file
git log --since="2 weeks ago" --author=jaderecent 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