Параллельная работа
Ветвление позволяет нам работать в нескольких параллельных рабочих пространствах.
Чтобы продемонстрировать это, давайте создадим две ветки: одну с именем 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
И зафиксируйте изменение с помощью команды add.
$ 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(-)
Теперь наш журнал выглядит так:

Мы добавили две разные строки текста в две разные ветки параллельно.