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 mybranch

  • Git merge inconveniences
  • git merge Already up to date when it is not
  • Git: false merge conflicts?
  • how can I customize git's merge commit message?
  • Merge command from Git removes files
  • git creates merge commit instead of using fast forward. Why?
  • Trying to understand advanced git branching
  • How do I resolve a conflict after git pull?
  • 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
    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 <>
    Date:   Mon Dec 26 22:07:50 2016 -0800
        Squashed commit of the following:
        commit 3120cbba4e94e0a81eed2f9ff42e7012cca996bf
        Author: G. Sylvie Davies <>
        Date:   Thu Dec 15 18:24:02 2016 -0800
        commit ccb522334464879b8f39824031c997b57303475d
        Merge: 6b85efb 026bf0c
        Author: G. Sylvie Davies <>
        Date:   Thu Dec 15 18:13:35 2016 -0800
        commit 6b85efbddbb74d49a096bfc54fd4df15e261b72f
        Author: G. Sylvie Davies <>
        Date:   Thu Dec 15 18:12:51 2016 -0800

    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.

    enter image description here

    Git Baby is a git and github fan, let's start git clone.