git show
git
用法
git show [<object>|<commit>:<path>]把一個提交的訊息和改動一起印出來;寫成 <commit>:<path> 就能取出檔案的舊內容而不動你的工作副本。
常用選項
| 選項 | 含義 |
|---|---|
| --stat | file summary instead of the full patch |
| --name-only | list the paths the commit touched |
| -s | message only, no diff |
| <commit>:<path> | print the file as it was in that commit |
| --pretty=fuller | show author and committer dates separately |
範例
git show HEADthe message and diff of the last commit
git show HEAD~2:src/app.tsprints an old version of a file without touching your copy
git show --stat v1.2.0what the tagged commit changed, file by file
難的地方在於復原有好幾種:把分支的指向挪走,和補一個反向提交,不是一回事。
怎麼看
- 方括號 [ ] 表示這部分可以不寫。
- 省略號 … 表示可以寫多個。
- 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。
常見問題
Q. git show 是做什麼的?
把一個提交的訊息和改動一起印出來;寫成 <commit>:<path> 就能取出檔案的舊內容而不動你的工作副本。
Q. 怎麼寫?
git show [<object>|<commit>:<path>] —— 方括號表示可以省略的部分。
Q. 值得記的選項有幾個?
這裡列了 5 個,完整列表在 man git。這條命令屬於git。
相關命令
man 手冊: man git-show