Home  >  Article  >  Development Tools  >  What is the difference between git rebase and merge?

What is the difference between git rebase and merge?

hzc
hzcOriginal
2020-06-12 16:21:469403browse

What is the difference between git rebase and merge?

merge and rebase

The two commands on the title: merge and rebase are both used to merge branches.

The rebase command and the principles of the two commands are not explained here. For detailed explanation, please refer here.

The following content mainly talks about the difference between the two in actual operation.

What is a branch

Branch is to facilitate the collaborative development of multiple people in the same project. For example: Everyone develops different functions without affecting each other during the development process of their respective branches. After completion, they are submitted to the develop branch. Greatly improves development efficiency.

Merge branches

Everyone creates a branch for development. When the development is completed and needs to be merged into the develop branch, the merge command needs to be used.

What is a conflict

When merging, conflicts may occur.

Conflicts occur because different branches modify the same location during merging. So when merging, git doesn't know which one you want to keep, so it raises a question (conflict reminder) and lets you manually select what you want to keep to resolve the conflict.

The difference between merge and rebase

1. The difference between git log after using merge and rebase. The merge command will not retain the commit of the merged branch:

What is the difference between git rebase and merge?

2. How to deal with conflicts:

  • (One brain) Use the merge command to merge branches, resolve the conflict, and execute git add. and git commit -m'fix conflict'. A commit will be generated at this time.

  • (Interactive) Use the rebase command to merge branches, resolve conflicts, execute git add . and git rebase --continue, no additional commits will be generated. The advantage of this is that it is 'clean' and there will be no meaningless commits to resolve the branch on the branch; the disadvantage is that if there are multiple commits in the merged branch, multiple conflicts need to be handled repeatedly.

3. The difference between git pull and git pull --rebase: git pull does two operations, namely 'get' and merge. Therefore, adding rebase means merging branches in the rebase method, and the default is merge.

Recommended tutorial: "

Git Tutorial"

The above is the detailed content of What is the difference between git rebase and merge?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn