Matt Fenwick
Matt Fenwick

Reputation: 49085

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

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).

Upvotes: 3

Views: 306

Answers (1)

xlembouras
xlembouras

Reputation: 8295

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.

Upvotes: 2

Related Questions