Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

squash more then two commits in sourcetree?

I have a large number of commits, about 20, that I've done since my last push to origin/master. I have never had more than one branch, master, and all commits were done on master. How can I squash all 20 commits into one commit, preferably using sourcetree? I want to do this so I can just push one commit to origin/master.

In sourcetree I have figured out to use the interactive rebase command in the repository menu. It brings up the exact list of commits I want to squash. I tried hitting the squash button repeatedly until it shows one commit containing all of them. But when I hit OK I end up with only the two most recent commits squashed. So even though the dialog seems to show it can squash multiple in practice I can't get it to work.

like image 891
mark-hahn Avatar asked Aug 03 '14 07:08

mark-hahn


People also ask

How do I squash multiple commits in SourceTree?

SourceTree for Mac Combine (squash) multiple commits together, or re-order them, simply by dragging & dropping. You can also change the commit message, or edit the content of the commits. Just right-click on a commit in the log and choose 'Rebase children of <sha> interactively' to kick the process off.

How could you squash multiple commits together without using?

You can do this fairly easily without git rebase or git merge --squash . In this example, we'll squash the last 3 commits. Both of those methods squash the last three commits into a single new commit in the same way. The soft reset just re-points HEAD to the last commit that you do not want to squash.

Should I squash all commits?

As a general rule, when merging a pull request from a feature branch with a messy commit history, you should squash your commits. There are exceptions, but in most cases, squashing results in a cleaner Git history that's easier for the team to read.


1 Answers

Easier solution (than a rebase):

Select the "origin/master" commit in the log entry, click on "Reset <branch> to this commit".

http://i.imgur.com/nWDzb6k.png

Use the default mixed mode.

http://i.imgur.com/bTaS5KD.jpg

Then add and commit: all your changes will be registered again in one new commit, that you will be able to push.

See git reset Demystified for more.

like image 86
VonC Avatar answered Sep 19 '22 18:09

VonC