Skip to content

Allow editing the commit message when squash-merging a PR #1023

Closed

Description

@g0tsimid

Describe the feature or problem you’d like to solve

When performing a squash and merge on a pull request through the web interface, you can edit the commit message and extended description. By default, this is prepopulated with a list of all of the commit messages included in the pull request. I often find myself deleting some of the lines from this section because the additional commits are usually related to feedback brought up during the code review, and would be irrelevant or confusing when viewing in the context of the final commit.

When merging a PR through the CLI, the same commit message is generated as the web interface, but there is no option to edit the commit message.

Proposed solution

Open the user's default terminal editor to allow the PR maintainer to enter the commit message. By default, prepopulate the editor with the default generated message so the user can easily just save and exit the editor to continue using the current behaviour.

SPEC: #1023 (comment)

Activity

  1. added
    enhancement
    on May 27, 2020
  2. mgabeler-lee-6rs commented on Jun 25, 2020

    @mgabeler-lee-6rs
    Contributor

    I'd like to be able to edit the commit message for all merges, not just squash ones.

    My use case: I want/need my merge commits to have a conventional commit format to support semrel automation

  3. chandlerc commented on Jul 1, 2020

    @chandlerc

    I think this is more serious than an "enhancement".

    In the GitHub web UI, the "squash and merge" button always opens a text box to prompt editing the commit message.

    The git pr merge --squash command gives no indication that it will directly commit without any option to edit the commit message. This is extremely surprising and results in a bad history for repositories. At the very least, there needs to be an unambiguous prompt prior to this happening as this is not a local operation or easily undone.

  4. krlmlr commented on Jul 13, 2020

    @krlmlr

    Could we also offer an -m or --message argument that allows editing the message in non-interactive mode?

  5. markov00 commented on Oct 5, 2020

    @markov00

    The @krlmlr suggestion for the non-interactive mode is also very useful when you use tools and conventions like conventional-commits and semantic-release where both title and body of the commit are used to detect the next semantic version to release.
    Actually, except for a github enterprise on-premise version, there is no way to check/lint the body message of a squashed PR and doing that manually or through some browser extension is not ideal.
    Adding a -m option will allow to squash the PR from the command line with a prelinted body and title

  6. added
    core
    on Oct 7, 2020
  7. andres-lowrie commented on Nov 11, 2020

    @andres-lowrie

    building off of @krlmlr 's comment. It could be useful to have the whole sub command take an argument that would be the message, similar to how git commit -m works; so something like this

    gh pr merge 123 -m "the commit message I want"
    

    This could work the same for all the flags too not just m , basically changing the usage to something like this

    USAGE
      gh pr merge [<number> | <url> | <branch>] [flags] [message]
    
  8. vilmibm commented on Jan 21, 2021

    @vilmibm
    Contributor

    I intend to merge #2810 but think this issue should remain open so we can discuss having an interactive prompt for this as well. @mislav do you recall if there was a technical reason for us not including that to begin with? @ampinsk do you recall if there was a UX reason?

  9. mgabeler-lee-6rs commented on Jan 22, 2021

    @mgabeler-lee-6rs
    Contributor

    In addition to interactive prompting mode, the other thing #1023 doesn't cover is setting the first line of the commit, which is important for some CI flows (e.g. commit message validation, semantic versioning release automation e.g. through conventional commits)

  10. vilmibm commented on Jan 23, 2021

    @vilmibm
    Contributor

    We just didn't get to adding an interactive prompt for this and agreed internally it's a good idea.

    The spec for this is converting the confirmation prompt from a y/N prompt to a select with options:

    Submit
    Edit Commit Message
    Edit Commit Author
    Cancel
    

    Editing the commit message should prepopulate the user's editor with a precomputed headline/body. The web UI splits out the headline as a separate input, but I think it's okay to have it be the top line of the file opened in the editor.

  11. added
    help wanted
    and removed
    core
    on Jan 23, 2021
  12. cristiand391 commented on Jan 24, 2021

    @cristiand391
    Contributor

    I'm working on this issue.

  13. rfkd commented on Jan 29, 2021

    @rfkd

    Is there any way to change the commit message "title" (as shown in git log --oneline)? The new --body argument introduced with #2810 only seems to append its value to the default title "Merge pull request #... from ..." instead of allowing to define the entire commit message.

  14. mgabeler-lee-6rs commented on Feb 17, 2021

    @mgabeler-lee-6rs
    Contributor

    I don't agree that #2980 resolves this

    When performing a squash and merge on a pull request through the web interface, you can edit the commit message and extended description

    #2980 only permits editing the body, not the first line of the message. It has some internal code for setting the "headline", but no ability to invoke that code from the CLI AFAICT:
    Compare:

  15. achimnol commented on Feb 22, 2021

    @achimnol

    It is great to heart that this feature is finally implemented.
    However, I just faced a caveat: editing the commit message is only prompted when pr merge is executed in the interactive mode ONLY, meaning that pr merge --squash still does not have chances to change the commit message interactively.
    I think this is an acceptable complexity trade-off for handling scripted usage and interactive usage, but at least this should be documented somewhere, e.g., "When you specify the merge method explicitly via --merge / --rebase / --squash arguments, it runs in the non-interactive mode and the commit message is automatically filled unless specified with the --body argument".

  16. Ashish-Pandey-Imprivata commented on Mar 16, 2021

    @Ashish-Pandey-Imprivata

    Any timelines to fix the issue of changing first line of commit message when doing pr merge operation? As others have mentioned before, there is a need to consolidate the comments during pr merge operation for those who follow Conventional Commit message format. Thanks for adding -b option for commit body though.

  17. mislav commented on Mar 17, 2021

    @mislav
    Contributor

    Thanks for the feedback, everyone. Reopening as a feature request to be able to edit the commit subject message as well as the commit body.

  18. reopened this on Mar 17, 2021
  19. Ashish-Pandey-Imprivata commented on Mar 17, 2021

    @Ashish-Pandey-Imprivata

    Thanks for the feedback, everyone. Reopening as a feature request to be able to edit the commit subject message as well as the commit body.

    Thanks a lot. Since I am not familiar with GH CLI release cycles, would it be possible to get a rough timeline on release when this feature would be available?

  20. mislav commented on Mar 18, 2021

    @mislav
    Contributor

    @Ashish-Pandey-Imprivata We don't know. If someone wants to step up and contribute the code for feature via a pull request, it might get released within the next few weeks. Otherwise, it's going to be whenever we find time to get to this.

    In the meantime, this manual approach will work with existing versions of GitHub CLI:

    gh api -XPUT --silent repos/:owner/:repo/pulls/NUMBER/merge -f merge_method=merge -f commit_title="TITLE" -f commit_message="MESSAGE"

    It can be saved as an alias:

    $ gh alias set merge-explicit '!gh api -XPUT --silent repos/:owner/:repo/pulls/$1/merge -f merge_method=merge -f commit_title="$2" -f commit_message="$3"'
    
    $ gh merge-explicit 123 "this is commit subject" "this is commit message" 
  21. Ashish-Pandey-Imprivata commented on Mar 18, 2021

    @Ashish-Pandey-Imprivata

    Thanks for your comment and suggestions for a good workaround in the meantime. Using "gh api" is slightly involved, but works fine.

  22. mislav commented on Jan 31, 2022

    @mislav
    Contributor

    This shipped in v2.4.0, forgot to close: f2d23d8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions