Merging on github with the "Squash and merge" option is tempting, but should be used with huge care. In a normal squash operation git retains the author information from the commits, but github replaces the information with the public  information of the account associated with the commits. Many accounts on github are configured to keep the email address and real name private. For the author entry in the git repository this is not acceptable, as we need to be able to track who committed a change.

If a committer is not sure if the github profile of the author is configured in a sane manner, follow the following procedure to squash and merge:

One-Time preparation:

Modify your git configuration of the repository to include the github pull requests. In my case this looks like this:

.git/config
[remote "github"]
        url = https://github.com/apache/netbeans.git
        fetch = +refs/heads/*:refs/remotes/github/*
        fetch = +refs/pull/*/head:refs/remotes/github/pr/*

Regular

You can now fetch from github and will also get the PRs - sample:

matthias@athena:~/src/netbeans$ git fetch github
remote: Enumerating objects: 409, done.
remote: Counting objects: 100% (409/409), done.
remote: Compressing objects: 100% (52/52), done.
remote: Total 418 (delta 198), reused 408 (delta 197), pack-reused 9
Receiving objects: 100% (418/418), 83.00 KiB | 765.00 KiB/s, done.
Resolving deltas: 100% (198/198), completed with 150 local objects.
From https://github.com/apache/netbeans
   166e2bb491c2..96c12bc480bb  master                                   -> github/master
 * [new branch]                release120                               -> github/release120
 * [new branch]                revert-2020-nb3986_create_class_on_paste -> github/revert-2020-nb3986_create_class_on_paste
 + c020b2aa67fe...a2424ced642b refs/pull/1983/head                      -> github/pr/1983  (forced update)
   97c51d4d68b6..67abcff2f999  refs/pull/2009/head                      -> github/pr/2009
 + a932efdfca76...4e436738f59a refs/pull/2012/head                      -> github/pr/2012  (forced update)
 + 89e505e7bf4f...3d094315588a refs/pull/2014/head                      -> github/pr/2014  (forced update)
 * [new ref]                   refs/pull/2018/head                      -> github/pr/2018
 * [new ref]                   refs/pull/2019/head                      -> github/pr/2019
 * [new ref]                   refs/pull/2020/head                      -> github/pr/2020
 * [new ref]                   refs/pull/2021/head                      -> github/pr/2021
 * [new ref]                   refs/pull/2022/head                      -> github/pr/2022
 * [new ref]                   refs/pull/2023/head                      -> github/pr/2023
 * [new tag]                   12.0-beta1                               -> 12.0-beta1
matthias@athena:~/src/netbeans$

Ensure your master branch is current (this assumes, that the git upstream branch is either the master branch of the github mirror of Apache NetBeans or the master branch from the primary Apache gitbox site):

git checkout master
git pull

Checkout the PR you want to squash and merge (here it is PR #1771):

git checkout github/pr/1771

Rebase the PR onto master

git rebase master

Do the squashing - get an overview how far back you need to go (the last 20 commits with author):

git log --pretty="%h%x09%ae%x09%s" -n 20

Do an interactive rebase (in this case the last 6 commits will be included):

git rebase -i HEAD~6

Your editor is opened with the commits listed - you can now apply different commands to  do a sane squasing, change the default `pick` to `s` (short for squash)

pick 213fefed1af0 [NETBEANS-3428] FlatLaf: UI delegates for editor and view [...]
s b66a05ff095c [NETBEANS-3428] FlatLaf: fix editor and view tabs painting is[...]
s 3ffacc5bc969 [NETBEANS-3428] FlatLaf: removed no longer needed class NbFla[...]
s 32852d80343b [NETBEANS-3428] FlatLaf: give HeapView better colors in FlatL[...]
s 952e39847f2e [NETBEANS-3428] FlatLaf: - increase major release version of [...]
s dc439be5df98 [NETBEANS-3428] FlatLaf: - avoid using `com.formdev.flatlaf.u[...]

Save the result and exit editor

You are asked to create a new commit message and prepares it by including all commit  messages of the commits you are squashing

Check the author (shown in the comment section at the bottom)

Save and exit editor

The summary of the new commit will be shown (here: c20b63503c98):

matthias@athena:~/src/netbeans$ git rebase -i HEAD~6
[losgelöster HEAD c20b63503c98] [NETBEANS-3428] FlatLaf: UI delegates for editor and view tabs in main window
 Author: Karl Tauber <karl@jformdesigner.com>
 Date: Tue Dec 10 19:52:42 2019 +0100
 17 files changed, 1546 insertions(+), 41 deletions(-)

Switch back to master

git checkout master

Merge (commit hash from above):

git merge c20b63503c98

Push

git push
  • No labels