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.

平行作業

分支允許我們在多個並行工作區中工作。

為了演示這一點,讓我們建立兩個分支,一個名為issue2,另一個名為issue3。然後切換到issue2

$ git branch issue2
$ git branch issue3
$ git checkout issue2
Switched to branch 'issue2'
$ git branch
* issue2
  issue3
  main

此時,我們的歷史紀錄如下:

Current history

接下來,將下面的粗體文本新增到myfile.txt檔案中。

Anyone can learn Git with this tutorial and Backlog add: Register a change in an index commit: Save the status of an index

然後提交更改。

$ git add myfile.txt
$ git commit -m "append description of the commit command"
[issue2 8f7aa27] append description of the commit command
  1 files changed, 2 insertions(+), 0 deletions(-)

現在我們的歷史紀錄如下:

Current history

接下來,切換到issue3分支。

$ git checkout issue3
Switched to branch 'issue3'

issue3分支目前與主分支具有相同的歷史紀錄和內容。它不會包括我們剛才所做的更改,因為它已提交給issue2分支。

將下面的粗體文本新增到myfile.txt檔案中。

Anyone can learn Git with this tutorial and Backlog add: Register a change in an index pull: Obtain the content of the remote repository

並使用新增指令來提交更改。

$ git add myfile.txt
$ git commit -m "append description of the pull command"
  [issue3 e5f91ac] append description of the pull command
    1 files changed, 2 insertions(+), 0 deletions(-)

現在我們的歷史紀錄如下:

Current history

我們已將兩行不同的文本,平行新增到兩個不同的分支。

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life