Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Squash to only one "proper" commit for github pull request

I have a repo on github which someone else (Bob, for the sake of argument) has issued a pull request for. His code's not perfect, so we go through a few rounds of markups. As I understand it, he commits and pushes to his pull-request for each set of marked up changes.

So my repository now looks like this:

master: ---o A (Chowlett            |            | pull-req:  o---o---o---o                B   C   D (all Bob) 

Commit SHAs and msgs are as follows:

A:

123456 Good commit <chowlett> 

B:

777ccc Fix the widget bug <bob> 

C:

888ddd Review markups <bob> 

D:

999eee Further markups <bob> 

I'm now happy to accept this pull request; but I'd rather the pre-markup versions weren't in my repo. Can I achieve all of the following; and how?

  • Merge B, C & D into my repo as a single commit
  • Generate the "Merge pull request #99 into ..." commit as well
  • Have github automatically close the pull request
like image 465
Chowlett Avatar asked Jul 09 '12 13:07

Chowlett


People also ask

Can I squash specific commits?

There is no explicit Git squash command. Instead, to squash git commits, the interactive git rebase is used. To squash all commits on a single branch, the interactive git rebase command must be passed one of two arguments: the id of the commit from which the branch split from its parent.

Should I squash commits before pull request?

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 do you squash commits on a pull request?

Pull requests with squashed commits are merged using the fast-forward option. To squash and merge pull requests, you must have write permissions in the repository, and the repository must allow squash merging. You can use squash and merge to create a more streamlined Git history in your repository.


1 Answers

Note that Bob doesn't have to squash his commits when he is making a GitHub PR.
Since March 2016, you can leave that operation to the maintainer (you) accepting your PR.

See "Squash your commits" and its new documentation

This is a new option which lets you force commit squashing on all pull requests merged via the merge button.

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

like image 176
VonC Avatar answered Oct 08 '22 21:10

VonC