目前我需要做:
git rebase -i f47adfa0向我显示:
pick 447a1cb Either left or right
pick ef35186 Introducing side effects
Run Code Online (Sandbox Code Playgroud)
然后,我将其修改为:
edit 447a1cb Either left or right
pick ef35186 Introducing side effects
Run Code Online (Sandbox Code Playgroud)
如果我要进行edit特定的提交(447a1cb在这种情况下),是否可以使用命令直接调用该状态?不必执行上述过程?
我想不出一个快速的方法来做到这一点。这是一种方法。无论提交发生在多远之前,它都会起作用,但请注意rebase吃掉沿途的所有合并。*
git checkout 447a1cb
<edit stuff>
git commit --amend
git checkout -
git rebase --onto @{-1} 447a1cb
Run Code Online (Sandbox Code Playgroud)
447a1cb请注意,我在第一步和最后一步中明确使用了上面的提交哈希;这当然可以用相对引用替换,例如HEAD^只要在两个步骤中引用相同的提交即可。
上面解释了:
HEAD^(最后一次提交的第一个父级,即返回的一个提交)及更早的提交。使用--onto将避免同时应用旧的提交,这可能会导致冲突或额外的提交。更多信息请参见man git-rebase。
虽然上述方法有效,但大多数时候我可能更喜欢交互式变基。
* 如果您正在编辑的提交后有合并,请考虑将--preserve-merges标记标记为git rebase(但请阅读BUGS部分man git-rebase)--rebase-merges标记git rebase,或者git replace --edit与 结合使用git filter-branch。更多信息请参见man git-replace和man git-filter-branch。