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