背景及应用场景
之前的提交[hash]因为某些原因,不能运行,需要提交一个patch。我想把这个patch打到[hash]的提交上?
定义
- [hash] : 表示值为hash的某次提交commit
- [hash'] : 表示[hash]的前一个提交commit
- patch : 这里和commit不一样,可以想成一个补丁,就是对历史的某个commit的打的一个补丁
步骤
- 准备好你的patch
- git stash: 暂存patch,一下才能做git rebase
- git rebase -i ([hash]前一个[hash']): 显示[hash']之前所有的提交
- 选择你要打patch的目标[hash],本例中就是第一个
- 将该条目中的
pick改为edit
- git stash pop: 弹出patch
- git add . 加入patch到暂存区
- git commit --amend:此步骤即重新将暂存区提交到该之前指定的[hash]里,并可以编辑(edit)提交信息
- git rebase --continue