Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I squash small, development commits into bigger ones?

There are (too) many questions regarding how to squash commits for git and other DVCS, such as:

  • Squash my last X commits together using Git
  • How to squash all git commits into one?
  • Joining various commits in one without merging
  • Is there a way to squash a number of commits non-interactively?
  • Can I squash commits in Mercurial?
  • With Mercurial, how can I "compress" a series of changesets into one before pushing?
  • ...

My question is, do I want to squash commits? Should I keep the detailed sequence of commits showing how a feature was developed, or should I rather squash them into one once the feature is finished, to keep the history cleaner?

like image 239
Petr Avatar asked Jan 28 '13 01:01

Petr


People also ask

Should commits be squashed?

Before you start, keep in mind that you should squash your commits BEFORE you ever push your changes to a remote repository. If you rewrite your history once others have made changes to it, you're asking for trouble… or conflicts.

When should you git squash?

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.

Should I squash or merge?

Merge vs.You should consider using squash if your team prefers a linear project history. This means that the history held by your main branch should not contain merges. A squash merge makes it possible to keep changes condensed to a single commit, supporting this strategy nicely.

Can I squash specific commits?

In the list of branches, select the branch that has the commits that you want to squash. Click History. Select the commits to squash and drop them on the commit you want to combine them with. You can select one commit or select multiple commits using Command or Shift .


1 Answers

Reasons for squashing commits:

  • A cleaner, simpler history.
  • A smaller history. Less baggage when cloning repos.
  • Removes "junk" commits, such as typo fixes.
  • Gives the opportunity to improve commit messages.

Reasons against squashing commits:

  • We can no longer follow the history of that feature/bugfix in order to learn how it was developed or see alternative solutions that were attempted but later replaced. (Cited from Mike Gerwitz's A Git Horror Story.)
  • It renders git bisect useless. If we find a bug in the software that was introduced by a single patch consisting of 300 squashed commits, we are left to dig through the code and debug ourselves, rather than having Git possibly figure out the problem for us. (Cited from Mike Gerwitz's A Git Horror Story.)

Please feel free to add other reasons to this wiki answer, if you don't want to give your own answer.

like image 165
2 revs, 2 users 80% Avatar answered Sep 24 '22 03:09

2 revs, 2 users 80%