问题
执行 git rebase -i 时,如果要回溯多个 commit,用 ~ 写法会很冗长:
bash
git rebase -i HEAD~~~~~~~~~ # 回溯 9 个 commit,太长了
解决方案
~ 后面直接跟数字即可:
bash
git rebase -i HEAD~9
HEAD~9 等价于 HEAD~~~~~~~~~,表示往前回溯 9 个 commit。
等价写法对比
| 写法 | 说明 |
|---|---|
HEAD~9 |
最常用,数字指定回溯数 |
@~9 |
@ 是 HEAD 的别名,更短 |
<commit-hash> |
直接指定某个 commit hash,rebase 到它之后的所有 commit |
推荐用 git rebase -i @~9 最简洁。