Quick way to combine a bunch of commits together (git)

185 views Asked by At

I have branches master and feature.

Feature has about 20 commits ahead of master.

I want to squash all commits together so when I merge I have one commit. Is there a way to do this with one command? I know I could do an interactive rebase; but I am looking for a command that makes this easy.

2

There are 2 answers

0
Mark Stickley On BEST ANSWER

Yes!

On the master branch:

git merge --squash feature-branch

0
Endre Simo On

You can use

git rebase -i {revision-number} 
git rebase --interactive {revision-number}

Where -i means that you are going to enter into the interactive mode. You specify the revision from which you want the merge to occur.

After entering the interactive mode you will select for the first one the pick option and for the others squash. This way you will combine the multiple commits from feature branch into a single one. Then you can do:

git checkout master
git merge feature

Here is a great explanation:

http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html