Skip to main content

Configuring commit squashing for pull requests

You can enforce, allow, or disable commit squashing for all pull request merges on GitHub.com in your repository.

You can configure pull request merge options on GitHub.com to meet your workflow needs and preferences for managing Git history. For more information, see "Configuring pull request merges."

有关 squash 合并的默认提交消息的信息,请参阅“关于拉取请求合并”。

  1. On GitHub.com, navigate to the main page of the repository.

  2. 在存储库名称下,单击 “设置”。 “存储库设置”按钮

  3. Under "Pull Requests", select Allow squash merging. This allows contributors to merge a pull request by squashing all commits into a single commit. The default commit message presented to contributors when merging is the commit title and message if the pull request contains only 1 commit, or the pull request title and list of commits if the pull request contains 2 or more commits.
    Pull request squashed commits

  4. Optionally, under Allow squash merging, use the dropdown to choose the format of the default squash commit message presented to contributors when merging. The default message uses the commit title and message if the pull request contains only 1 commit, or the pull request title and list of commits if the pull request contains 2 or more commits. You can also choose to use just the pull request title, the pull request title and commit details, or the pull request title and description. Screenshot of emphasized default squash message dropdown

If you select more than one merge method, collaborators can choose which type of merge commit to use when they merge a pull request. 如果你的存储库中有需要线性提交历史记录的受保护分支规则,则必须允许 Squash 合并和/或变基合并。 有关详细信息,请参阅“关于受保护的分支”。

Further reading