git reflog
git
用法
git reflog [show] [<ref>]记录 HEAD 和各分支待过的每个位置;被 reset --hard 或删分支弄丢的提交就在这里找,条目默认 90 天后过期,而且这份记录只在你本机。
常用选项
| 选项 | 含义 |
|---|---|
| show <ref> | the positions of one branch instead of HEAD |
| --date=iso | real timestamps instead of relative ones |
| -n <n> | only the last n entries |
| HEAD@{n} | the commit HEAD pointed at n moves ago |
| expire --expire=now --all | wipe the log, which also gives up the safety net |
示例
git reflogevery position HEAD has had, newest first
git reflog --date=iso -n 20the last twenty moves with real dates
git reset --hard HEAD@{1}undoes the reset you just regretted
难的地方在于撤销有好几种:把分支的指向挪走,和补一个反向提交,不是一回事。
怎么看
- 方括号 [ ] 表示这部分可以不写。
- 省略号 … 表示可以写多个。
- 选项区分大小写——有些命令里 -r 和 -R 不是一回事。
常见问题
Q. git reflog 是做什么的?
记录 HEAD 和各分支待过的每个位置;被 reset --hard 或删分支弄丢的提交就在这里找,条目默认 90 天后过期,而且这份记录只在你本机。
Q. 怎么写?
git reflog [show] [<ref>] —— 方括号表示可以省略的部分。
Q. 值得记的选项有几个?
这里列了 5 个,完整列表在 man git。这条命令属于git。
相关命令
man 手册: man git-reflog