并行作业
分支允许我们在多个并行工作区中工作。
为了演示这一点,让我们创建两个分支,一个名为issue2
,另一个名为issue3
。然后切换到issue2
。
$ git branch issue2
$ git branch issue3
$ git checkout issue2
Switched to branch 'issue2'
$ git branch
* issue2
issue3
main
此时,我们的历史记录如下:

接下来,将下面的粗体文本添加到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(-)
现在我们的历史记录如下:

接下来,切换到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(-)
现在我们的历史记录如下:

我们已将两行不同的文本,并行添加到两个不同的分支。