Squashing commits

You can use GitHub Desktop to squash commits in your branch's history.

About squashing a commit

Squashing allows you to combine multiple commits in your branch's history into a single commit. This can help keep your repository's history more readable and understandable.

Squashing a commit

  1. 在 GitHub Desktop 中,单击 Current Branch(当前分支)当前分支下拉菜单
  2. In the list of branches, select the branch that has the commits that you want to squash.
  3. 单击 History(历史记录)边栏中选择的历史记录选项卡
  4. Select the commits to squash and drop them on the commit you want to combine them with. You can select one commit or select multiple commits using or Shift. squash drag and drop
  5. Modify the commit message of your new commit. The commit messages of the selected commits you want to squash are pre-filled into the Summary and Description fields.
  6. Click Squash Commmits.
  1. 在 GitHub Desktop 中,单击 Current Branch(当前分支)当前分支下拉菜单
  2. In the list of branches, select the branch that has the commits that you want to squash.
  3. 单击 History(历史记录)边栏中选择的历史记录选项卡
  4. Select the commits to squash and drop them on the commit you want to combine them with. You can select one commit or select multiple commits using Ctrl or Shift. squash drag and drop
  5. Modify the commit message of your new commit. The commit messages of the selected commits you want to squash are pre-filled into the Summary and Description fields.
  6. Click Squash Commmits.

Error messages when squashing commits

When you squash commits, you may see one of the following notifications or error messages.

  • A notification states that the requested change to the branch will require a force push to update the remote branch. Force pushing alters the commit history of the branch and will affect other collaborators who are working in that branch. Select Begin Squash to start the squash, and then click Force push origin to push your changes.

    squash force push dialog

  • An error states that the squash failed because there is a merge commit among the squashed commits.

    reorder merge commit dialog

  • A notification is shown indicating that there are uncommitted changes present on your current branch. Select Stash Changes and Continue to store the changes and proceed, or select Close to dismiss the message and commit the changes. When there are no longer any uncommitted changes you can squash your commits.

    squash stash dialog

此文档对您有帮助吗?隐私政策

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。