Clean, clean git PR seal and merge, in one commit

Most of the time we see a PR in the repos and then a merge commit of that PR that simply says "Merged pull request from C # XXX from ...".

But lately I saw a compact version of this where the avatars of the pull initiator and the committer overlap, and only one clean commit is shown in the history:

enter image description here

How can I do that?

What I've tried and doesn't work:


UPDATE

An example of what it looks like when one of my PRs was folded like this:

enter image description here

Results in:

enter image description here

+3


source to share


2 answers


April 2016 Update

GitHub introduced the squash commit on merge option , so you can do it directly from your web interface:

Squash and merge

Old solution

Just found this workflow from the Meteor team (coincidentally, thanks @Emily ):

When you view a pull request in the GitHub web interface, there is a very attractive "merge" button. NEVER USE THE MERGE BUTTON. This is an attractive nuisance . This makes the git history more complex than necessary: ​​if the PR was filed a month ago, the commit parent would be a very old version, resulting in more lines than needed in the graphical representation of the git history. Also, if you use the merge button, this means you have never checked the code or tried to try it! Below is the best way to get land dump requests.

First, in your repository, find the [remote "origin"]

file section .git/config

and add the following line:

fetch = +refs/pull/*/head:refs/remotes/origin/pr/*

      



Make sure to add it before the existing sample line. Now, every time you git fetch, you will get all pull requests to the repo updated! This is a one-time change and will give you direct access to PR forever.

Then you can git checkout pr/XXX

work with the changes simply and directly. A git push origin

after picking cherries will create a compact PR:

git checkout pr/32
# ... test changes ...
git checkout master
git cherry-pick pr/32
git push 

      

enter image description here

The only downside is that GitHub won't automatically delete PR branches when closed, but it's just one click away and you get a much nicer story in return.

If the PR is multiple commits, your best bet is to check it out, rebase it to the development branch , make any other changes you need, and merge them back into the development branch with an explicit merge. This is similar to what the GitHub merge button does, except that the merge button does not do a VERY IMPORTANT reinstall operation and therefore leaves ugly spaghetti in the git project history. To do this, run:

git checkout pr/32; git rebase devel; git checkout devel; git merge --ff-only pr/32

      

Then check and click.

If you want to merge some commits into a single commit, you can use an interactive rebase by running git rebase -i devel

. Some tutorials: http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html https://www.atlassian.com/git/tutorials/rewriting-history/git-reflog

Unfortunately, GitHub is not smart enough to detect that you have merged the PRs manually, so you need to manually comment and close the issue with a link to the corresponding commit. Also, make sure the merge commit message contains Fixed #123

.


UPDATE: Another update was made by Kahmali Rose which allows GitHub to detect that the PR has been merged, pretty much as if the evil merge button was clicked: make sure you rebuild and merge instead of cherry picking .

+5


source


If the PR is just one commit, you can cross it out to the master branch (or whatever branch you merge the PR into). So for example:

$ git checkout -b branch-for-pr master
$ git pull <fork url> <pr branch name>
$ git checkout master
$ git cherry-pick branch-for-pr

      



Alternatively, you can reinstall the PR branch on top of master to allow fast switching (which will skip the merge commit):

$ git checkout -b branch-for-pr master
$ git pull <fork url> <pr branch name>
$ git rebase master
$ git checkout master
$ git merge --ff-only branch-for-pr

      

+1


source







All Articles