Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github squash commits from web interface on pull request after review comments?

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:

  • Make local commits, working on feature
  • Squash commits
  • Make Pull Request
  • Receive review comments
  • Update PR appropriately

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?

like image 500
enderland Avatar asked Mar 11 '16 19:03

enderland


People also ask

Can you squash commits on GitHub website?

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.

Can I squash commits in pull request?

Under "Pull Requests", select Allow squash merging. This allows contributors to merge a pull request by squashing all commits into a single commit.

Should I squash commits before pull request?

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!

Should I squash commits or not?

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.


1 Answers

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):

https://help.github.com/assets/images/help/pull_requests/squash-and-merge.png

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:

  • If it works without conflict, the merge (or here, the merge --squash: see "In git, what is the difference between merge --squash and rebase?") will be created automatically.
  • If there is any conflict, the merge is not created, and the maintainer has the option to reject for now the PR, asking the contributor to do the work of squashing the commits and amending the PR.

This is really like what exists now, except GitHub has added the --squash to their merge command. Nothing more.

like image 119
VonC Avatar answered Sep 21 '22 02:09

VonC