跳至主要内容

在 GitHub Desktop 中压缩提交

您可以使用 GitHub Desktop 在分支的历史记录中压缩提交。

平台导航

关于压缩提交

压缩可将分支历史中的多个提交合并为一次提交。这有助于使仓库的历史更易阅读和理解。

压缩提交

  1. 在 GitHub Desktop 中,点击 当前分支

    Screenshot of the repository bar. A button, labeled "Current Branch" with a downward arrow indicating a dropdown menu, is outlined in orange.

  2. 在分支列表中,选择包含您想要压缩的提交的分支。

  3. 在左侧边栏,单击 历史记录

    Screenshot of the "History" tab in the sidebar. Above a list of commits, the tab button, labeled "History", is highlighted with an orange outline.

  4. 选择要压缩的提交,并将其拖放到您想要合并的提交上。

    您可以使用 CommandShift 选择单个提交或多个提交。

    您可以使用 CtrlShift 选择单个提交或多个提交。

    Screenshot of a list of commits in the "History" tab. The cursor hovers over a commit, highlighted in blue. A hover-over box shows "Squash 2 commits".

  5. 修改新提交的提交信息。您想要压缩的所选提交的提交信息会预填到 概要描述 字段中。

  6. 点击 压缩提交

压缩提交时的错误信息

当您压缩提交时,可能会看到以下通知或错误信息之一。

  • 会出现一条通知,说明对分支的请求更改需要强制推送才能更新远程分支。强制推送会更改该分支的提交历史,并会影响在该分支上工作的其他协作者。选择 开始压缩 开始压缩,然后点击 强制推送 origin 推送您的更改。
  • 错误提示压缩失败,因为在要压缩的提交中存在合并提交。
  • 会显示一条通知,指示您当前分支上存在未提交的更改。选择 暂存更改并继续 将更改保存并继续,或选择 关闭 关闭消息并提交更改。当不再有未提交的更改时,您即可压缩提交。

延伸阅读

© . This site is unofficial and not affiliated with GitHub, Inc.