Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: simplest way of squashing commits on master [duplicate]

Tags:

git

github

Possible Duplicate:
How can I squash my last X commits together using git?

I have a project hosted on GitHub and I have a local clone. I have a load of small commits that I have already pushed up to GitHub. This has all been done using the default *master branch.

I got confused between merge --squash and rebase etc... What is the most straightforward way of combining several historial commits in to one commit so that it pushes up to GitHub?

like image 631
Gabe Avatar asked Nov 21 '11 15:11

Gabe


People also ask

Should you squash commits to master?

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.

How could you squash multiple commits without?

To "squash" in Git means to combine multiple commits into one. You can do this at any point in time (by using Git's "Interactive Rebase" feature), though it is most often done when merging branches. Please note that there is no such thing as a stand-alone git squash command.


1 Answers

Before starting, you should make sure that git status is clean (i.e. there's no output from that command) to avoid losing work. The simplest way to do what you want is probably:

git reset --soft <LAST-COMMIT-THAT'S-OK> git commit -m 'Many squashed commits' git push --force origin master 

You should bear in mind that this is rewriting history (that's why you need the --force option to git push) so you should avoid this if anyone else might have cloned or pulled from your repository. For some more alternatives, see this question and its answers:

  • Squash my last X commits together using Git
like image 179
Mark Longair Avatar answered Oct 06 '22 13:10

Mark Longair