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

What is the difference between rebase and merge in git?

WBOY
WBOYOriginal
2022-01-07 14:40:0540727browse

Difference: 1. Rebase puts the current commit at the end of the public branch, merge merges the current commit with the public branch; 2. After using the merge command to resolve the conflict, a commit will be generated, and No additional commits will be generated after using the rebase command to resolve conflicts.

What is the difference between rebase and merge in git?

The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.

What is the difference between rebase and merge in git

Rebase will put the commit of the current branch at the end of the public branch, so it is called Rebase. It's like pulling this branch off the public branch again.

For example: If you pull a feature branch from master, and then submit a few commits, and someone happens to merge the things he developed into master, then there will be more masters than when you pulled the branch. Several commits, if you rebase master at this time, your current commits will be placed behind that person's commit.

What is the difference between rebase and merge in git?

merge will merge the public branch with your current commit to form a new commit

What is the difference between rebase and merge in git?

After using merge and rebase, the difference between git log is that the merge command will not retain the commit of the merged branch:

What is the difference between rebase and merge in git?

How to handle conflicts:

  • (One brain) Use the merge command to merge branches, resolve conflicts, 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.

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 study: "Git Tutorial"

The above is the detailed content of What is the difference between rebase and merge in git?. 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