If I have a commit history like this:
A-B-C-------G-H-J-K (master)
\ /
D-E-F
how can I squash commits between A and K into one commit Z:
A-Z-K (master)
?
First, execute:
git rebase -i A
This will show a list of commits in a text editor, starting with B and ending with K.
You will have to change the text pick
in front of commits C, D, E, F, H and J to s
or squash
. Do not change pick
in front of B or K. Please note that the commit G should be missing, because it is a merge commit.
Finally, save and exit the editor. This will start the actual rebasing.
The result will be this:
A-Z-K' (master)
\
B-C-------G-H-J-K (no branch)
\ /
D-E-F
The part that is on no branch will eventually be removed by a garbage collection.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With