Can Git merge –squash preserve commit comments?
Is there a way of automatically adding all the commit comments from the squashed
mybranch commits when doing a
git merge --squash mybranch
so that the single commit contains a concatenation of all the commit comments from
One Solution collect form web for “Can Git merge –squash preserve commit comments?”
I think that’s what “git merge –squash” does automatically! Just do the commit with “git commit –no-edit” and I think that’s what you’ll get. I see all the commit messages inside .git/SQUASH_MSG immediately after I run the “git merge –squash” command. Do you?
Personally, I squash into master, but then force-push the result back to my topic branch. This way my final commit can be code-reviewed via pull-request.
Live example (try these exact commands, this uses my demo server, and really works):
git clone http://vm.bit-booster.com/bitbucket/scm/bb/rebase-example-2.git cd rebase-example-2 git checkout branch git reset --hard origin/master git merge --squash origin/branch git commit --no-edit git show commit 74656c51212526af49382c985419244737141217 Author: G. Sylvie Davies <email@example.com> Date: Mon Dec 26 22:07:50 2016 -0800 Squashed commit of the following: commit 3120cbba4e94e0a81eed2f9ff42e7012cca996bf Author: G. Sylvie Davies <firstname.lastname@example.org> Date: Thu Dec 15 18:24:02 2016 -0800 b2 commit ccb522334464879b8f39824031c997b57303475d Merge: 6b85efb 026bf0c Author: G. Sylvie Davies <email@example.com> Date: Thu Dec 15 18:13:35 2016 -0800 m commit 6b85efbddbb74d49a096bfc54fd4df15e261b72f Author: G. Sylvie Davies <firstname.lastname@example.org> Date: Thu Dec 15 18:12:51 2016 -0800 b1
At this point I recommend doing a “git push –force-with-lease” to get this squashed commit up to your remote topic branch ready for code-review.
Note: I do one fancy thing in the example. I’m actually squashing into origin/master, not local master, and I first do “git checkout branch” and “git reset –hard origin/master”. This keeps my local master unperturbed by this operation, so that whatever I might be working on there is left alone.
I’m on Git 2.7.4. Maybe older gits behave differently, I don’t know.
If you want to do this all in Web UI, and you happen to be using Atlassian Bitbucket Server (the on-premises version), you can install my Bit-Booster paid add-on, and hit the big “Squash” button it puts on pull-requests. It does the exact same thing, except that only non-merge commit messages are concatenated.