6

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)

?

timotei
  • 63
  • 1
  • 5
  • Useful link - [Combining multiple commits into one using git rebase](http://feeding.cloud.geek.nz/posts/combining-multiple-commits-into-one/) – timotei Feb 13 '13 at 13:47

1 Answers1

5

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.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
  • 1. What I have to do with commit B (live pick or change to squash)? 2. Is a rebase prosess replacing squashed commits or not? – timotei Feb 13 '13 at 11:46