How do I edit after squashing while doing an interactive rebase?

痴心易碎 提交于 2019-12-10 18:06:46

问题


I can't figure out how to get access to the results of a squashed commit during a rebase. I would like to be able to edit the commit after 2 commits have been squashed into the previous one. My rebase file looks like this:

p f70f90f ... some message ...
s 514ee77 ... some message ...
s ab01b05 ... some message ...
                                <-- want to edit 3 commits here!
p b109cc1 ... some message ...

I have already tried:

e f70f90f ... some message ...
s 514ee77 ... some message ...
s ab01b05 ... some message ...
p b109cc1 ... some message ...

But that lets me edit the first commit, then squashes the next two.

And:

p f70f90f ... some message ...
s 514ee77 ... some message ...
s ab01b05 ... some message ...
p b109cc1 ... some message ...

But that takes me straight into my text editor to edit the commit message for the last 3 commits, without giving me a chance to edit the commit itself.

I believe I could solve this issue using two rebases: 1) in which I squash, and 2) in which I edit. But the branch has a sufficient number of following commits that rebasing takes quite a while.

How do I do this in a single rebase? Or is there another, more appropriate solution?

(I am aware of the issues with rebasing publicly visible work, those aren't problems for this project).


回答1:


You could stop for editing on the third commit

p f70f90f ... some message ...
s 514ee77 ... some message ...
e ab01b05 ... some message ...
p b109cc1 ... some message ...

that way you stop at ab01b05 for editing. So if you

git reset --soft HEAD^

you can then do your changes. Then

git commit --amend

will squash the changes to the last commit (which now is the squash of f70f90f and 514ee77)

and you are set.

After that a

git rebase --continue

will take you to the next step of your rebase.



来源:https://stackoverflow.com/questions/20129946/how-do-i-edit-after-squashing-while-doing-an-interactive-rebase

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!