Let's say I have a commit history with 5 commits. I know that I can rebase my commits locally when making a pull request which will then have them rebased into a single commit.
A common use case for this is:
I can do this locally on my machine and then push my change again (using -f since the rebase makes it out of sync with the remote). This is kind of annoying.
However, this requires that I do a rebase every time I address review comments - is there any way I can do this from the web interface?
Or maybe my workflow is wrong, should I be amending each of my "review comments" commits directly onto the main PR commit?
Squashing a commitIn GitHub Desktop, click Current Branch. 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.
Under "Pull Requests", select Allow squash merging. This allows contributors to merge a pull request by squashing all commits into a single commit.
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. Potentially lots of them!
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.
You don't have to do any rebase/squashing locally anymore: just push your commit to your PR branch.
The owner of the original repo, if he/she chose to, will squash those commits for you (since March 2016):
See "Squash your commits" and the documentation: it does allow for a new workflow, both for you the contributor, and the maintainer of the original repo.
As I comment below: it will be implemented like the merge of a PR is implemented:
merge --squash
: see "In git, what is the difference between merge --squash
and rebase
?") will be created automatically. This is really like what exists now, except GitHub has added the --squash
to their merge command. Nothing more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With