Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I squash commits between A and K into one commit Z

Tags:

git

squash

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)

?

like image 406
timotei Avatar asked Oct 05 '22 01:10

timotei


1 Answers

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.

like image 158
Daniel Hilgarth Avatar answered Oct 10 '22 01:10

Daniel Hilgarth