If you're like me, then you tend to follow the ultra-conservative practice of "commit early, commit often" when using
However, if you work on a collaborative software project, some people may not care for all of those small, intermediate commits to clutter up the commit history on the main project repo. In these situations,
First off, I would recommend that teams always work in local repos forked from the main project repo. My reasoning is that this allows developers to mess up their local fork without affecting the main project, which users may still be cloning or pulling from in order to use the software. You can use a devel branch for this, but I like to be safe.
Okay, say you are working in your own forked repo, and you have committed 47 times while trying to fix a particular bug (we'll call it issue #100). If you want to squash all of these intermediate commits into 1 commit, then you can use
[sourcecode language="bash"]
$ git rebase -i HEAD~47
$ git commit --ammend -m "Fixing Issue #100"
$ git push origin master
[/sourcecode]
Once you have committed your squashed issue fix to your forked repo, you can issue a pull request to the main repo so that your software team can evaluate your issue fix.
Using
git
. If so, I applaud you. It's important to be sure you are keeping track of your work, and if you push your commits back to GitHub, Bitbucket, or GitLab that's even better. No one wants to do a day's worth of software development work, only to wake up the next morning to a local hard drive failure.However, if you work on a collaborative software project, some people may not care for all of those small, intermediate commits to clutter up the commit history on the main project repo. In these situations,
git
provides a great command rebase
. rebase
will allow you to squash your commits into something more easily reviewed by the code team when you issue your pull request.First off, I would recommend that teams always work in local repos forked from the main project repo. My reasoning is that this allows developers to mess up their local fork without affecting the main project, which users may still be cloning or pulling from in order to use the software. You can use a devel branch for this, but I like to be safe.
Okay, say you are working in your own forked repo, and you have committed 47 times while trying to fix a particular bug (we'll call it issue #100). If you want to squash all of these intermediate commits into 1 commit, then you can use
rebase
in the following way:[sourcecode language="bash"]
$ git rebase -i HEAD~47
$ git commit --ammend -m "Fixing Issue #100"
$ git push origin master
[/sourcecode]
Once you have committed your squashed issue fix to your forked repo, you can issue a pull request to the main repo so that your software team can evaluate your issue fix.
Using
rebase
to squash commits is quick and easy, and it makes the task of evaluating your work easier when the team gets together to discuss your pull request. It's a win-win and a great way to show your expertise and professionalism!