Skip to main content
  1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. 如何使用 Git
  6. 如何在 Git 中管理历史记录
  7. 组合提交
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

组合提交

请转至您之前下载的git-tutorial/tutorial5目录。

当您检查此存储库的历史记录时,它将如下所示:

Current history

我们将把“append description of the commit command”和“append description of the pull command”这两个提交组合成一个提交。

为此,我们将使用 git rebase -i 命令

$ git rebase -i HEAD~~

当您默认的文本编辑器打开时,您将处于 rebase-interactive 模式。它会显示从 HEADHEAD 的提交~~,如下所示:

pick 9a54fd4 append description of the commit command
  pick 0d4a808 append description of the pull command

  # Rebase 326fc9f..0d4a808 onto d286baa
  #
  # Commands:
  #  p, pick = use commit
  #  r, reword = use commit, but edit the commit message
  #  e, edit = use commit, but stop for amending
  #  s, squash = use commit, but meld into previous commit
  #  f, fixup = like "squash," but discard this commit log message
  #  x, exec = run command (the rest of the line) using shell
  #
  # If you remove a line here THAT COMMIT WILL BE LOST.
  # However, if you remove everything, the rebase will be aborted.
  #

在第二行,将单词pick更改为squash,然后保存并退出。

然后编辑器将提示您编辑这个新形成的提交的提交消息。编辑提交消息,然后保存并退出。

前两个提交现在被压缩成一个新的提交。

通过使用 git log 命令来检查历史日志,验证结果。

Organize commit

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life