Skip to main content
  1. Learn
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Как использовать Git
  6. Как использовать ветвление в Git
  7. Решение конфликта слияния
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Решение конфликта слияния

Далее давайте сольем ветки issue2 и issue3, которые мы создали на последнем шаге, в основную ветку.

Сначала переключитесь на main и выполните слияние с issue2, используя ускоренное слияние.

$ git checkout main
Switched to branch 'main'
$ git merge issue2
Updating b2b23c4..8f7aa27
Fast-forward
myfile.txt |    2 ++
  1 files changed, 2 insertions(+), 0 deletions(-)

Теперь журнал выглядит так:

Current history

Затем попробуйте слить issue3 с main.

$ git merge issue3
Auto-merging myfile.txt
CONFLICT (content): Merge conflict in myfile.txt
Automatic merge failed; fix conflicts and then commit the result.

В этом случае Git обнаружил конфликт, поскольку файл myfile.txt имеет разное содержимое в одной и той же строке в каждой ветке и не может автоматически объединить issue3 с main.

Файл myfile.txt теперь будет выглядеть примерно так:

Anyone can learn Git with this tutorial and Backlog
add: Register a change in an index
<<<<<<< HEAD
commit: Save the status of an index
=======
pull: Obtain the content of a remote repository
>>>>>>> issue3

Вы найдете маркеры, добавленные в файл myfile.txt Git, с информацией о конфликте. Мы должны вручную решить конфликт, как показано ниже.

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

Как только конфликт будет решен, зафиксируйте изменение.

$ git add myfile.txt
$ git commit -m "merge issue3 branch"
# On branch main
nothing to commit (working directory clean)

И журнал будет выглядеть так:

Current history

Вы можете видеть, что в результате решения конфликта была создана новая фиксация слияния. И основная ветка теперь указывает на последнюю фиксацию слияния. Это неускоренное слияние.

Smarter teamwork, delivered

Get practical advice, workflow guides, and proven strategies to help your team adopt tools fast and stay organized.