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/tutorial4目錄。

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

Current history

我們將在主分支中建立一個新提交,它是同一儲存庫不同分支上提交的副本。在這種情況下,讓我們複製附有append description of the commit command訊息的提交。

切換到主分支。使用 git cherry-pick 指令,並為append description of the commit command指定 commit hash。

提交哈希(hash)99daed2可能因您的本地儲存庫而異。您可以透過在該分支中執行 git 日誌指令,來獲得提交哈希值。尋找您本地儲存庫的提交哈希,並改用該提交哈希。

$ git checkout main
  Switched to branch 'main'
$ git cherry-pick 99daed2
  error: could not apply 99daed2... commit
  hint: after resolving the conflicts, mark the corrected paths
  hint: with 'git add <paths>' or 'git rm <paths>'
  hint: and commit the result with 'git commit'

如您所見,發生了衝突。手動解決該衝突,並繼續提交更改。

$ git add sample.txt
$ git commit

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life