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.

把分支合併到主分支

接下來,讓我們把您剛才建立的分支 (即issue1) 和它的提交,合併到main

$ git checkout main
Switched to branch 'main'

合併前,開啟myfile.txt檔案,並查看檔案內容。您會看到這個:

Anyone can learn Git with this tutorial and Backlog

正如您所看到的,我們在上個步驟中對issue1所做的修改,並沒有包含在主分支的myfile.txt檔案中。

當您使用 git merge 指令時,指定的提交將與活動分支合併。使用以下指令,我們現在可以合併。

$ git merge issue1
Updating 1257027..b2b23c4
Fast-forward
myfile.txt |    1 +
1 files changed, 1 insertions(+), 0 deletions(-)

主分支的位置現在將移動到issue1的位置,執行快轉合併。

Current history

最後,讓我們確認myfile.txt檔案的內容。開啟myfile.txt,您會看到我們提交給issue1分支的新行,現在位於主分支上。

Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life