如何将交互式rebase的提交编辑为未提交? [英] How do I edit a commit with interactive rebase as uncommited?
本文介绍了如何将交互式rebase的提交编辑为未提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用交互式资源库来编辑先前的提交,但是当我进入该提交的编辑模式时,所有文件都已提交.
I would like to use an interactive rebase to edit a previous commit, but when I enter the edit mode for that commit all the files have been committed.
我知道我可以进行更改并修改提交,但是我希望所有更改最初都未提交(暂存或其他),因此我可以对其进行编辑,就好像它最初提交之前一样.这可能吗?
I know I can make changes and amend the commit but I want all the changes uncommitted initially (staged or otherwise) so I can edit it as if it was moments before it was originally committed. Is this possible?
推荐答案
想象git rebase --interactive
给出了以下列表:
pick 3d15626 first
pick 7911b8b second
pick 60d94b4 third
,现在您要在未提交状态下编辑第二个提交.为此,请更改其行,如下所示:
and you now want to edit the second commit in its un-committed state. For this change its line like the this:
pick 3d15626 first
exec git cherry-pick --no-commit 7911b8b && false
pick 60d94b4 third
此行的作用:
- 不是正常选择提交,而是执行
git cherry-pick
-
git cherry-pick
将对索引和工作树应用第二"提交(请注意使用相同的提交哈希),预加载提交消息但不提交(--no-commit
) -
&& false
通过返回失败的退出代码来确保执行的命令失败".这迫使git rebase
在此行之后中断,以让您解决"问题,即您现在可以编辑提交 - 完成编辑后,可以再次
git commit
.由于git cherry-pick
,编辑器将自动包含原始提交消息.
- 在提交了提交并且索引再次干净之后,您可以继续使用
git rebase --continue
- instead of picking the commit normally
git cherry-pick
is executed git cherry-pick
will apply the "second" commit (note the same commit hash used) to the index and the working tree, preload the commit message but not commit (--no-commit
)&& false
ensures that the executed command "fails" by returning a failing exit code. This forcesgit rebase
to break after this line to let you "fix" the problem, i.e. you can now edit the commit- after you are done editing you can
git commit
it again. The editor will automatically contain the original commit message thanks togit cherry-pick
- after you committed the commit and the index is clean again you can continue with
git rebase --continue
这篇关于如何将交互式rebase的提交编辑为未提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文