16

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.

mark-hahn
  • 411
  • 4
  • 15
  • 1
    This question has also been [asked at Atlassian Answers](https://answers.atlassian.com/questions/301907/interactive-rebase-in-sourcetree-windows-doesnt-work-properly-at-all). No solution yet. – Jon Onstott May 22 '15 at 19:21

1 Answers1

17

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, that did it. So I guess it moved all changes since origin into the working copy? Is this correct? – mark-hahn Aug 03 '14 at 20:33
  • @mark-hahn it reset the index while keeping your working-tree intact, allowing you to register again *all* modifications in a new commit. – VonC Aug 03 '14 at 20:34
  • Oh, I see. It put them into the index which is what was committed. I'm used to committing directly from the workspace. Maybe I still don't understand. I'll keep studying this. – mark-hahn Aug 03 '14 at 20:37
  • @mark-hahn yes, http://git-scm.com/blog/2011/07/11/reset.html is a good resource to understand `git reset`. – VonC Aug 03 '14 at 20:37
  • Can I use soft mode like [this answer](http://stackoverflow.com/a/5201642/538763)? What's the difference? – crokusek Mar 16 '17 at 21:51
  • @crokusek yes, it is generally used to squash commits. See also http://stackoverflow.com/q/5203535/6309 – VonC Mar 16 '17 at 22:19