1. Learn center
  2. Software Development
  3. Guides
  4. Git tutorial
  5. 如何使用 Git
  6. 如何在 Git 中管理歷史紀錄
  7. 組合提交
Git

Project and code management together.

Try it free

組合提交

請前往您之前下载的git-tutorial/tutorial5目錄。

當您檢查此儲存庫的歷史紀錄時,它將如下所示:

Current history

我們將把append description of the commit commandappend 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