Home  >  Article  >  Development Tools  >  The difference between git merge and rebase

The difference between git merge and rebase

(*-*)浩
(*-*)浩Original
2019-10-22 13:32:529701browse

Connect to Git branch creation and merging. When merging branches, there are two ways: git merge and git rebase.

The difference between git merge and rebase

git merge: Merge and submit two branches into a new submission, and the new submission has 2 parents.

git rebase: will cancel each submission in the branch and store them temporarily, then update the current branch to the latest origin branch, and finally apply all submissions to the branch .

git merge

Specific operations: bob modified 2 times in index1.html and submitted it to the remote warehouse; lilei modified 2 times in index.html times and submit it to the remote warehouse; bob pulls the remote warehouse (git fetch origin dev) and merges it. The branch structure is as follows:

The difference between git merge and rebase

It can be seen that the two branches are merged, and the 93a6d33 commit has 2 parents (135b375 and 8b61b04).

git rebase

Specific operations: lilei modified 2 times in index.html and submitted it to the remote warehouse; bob modified 2 times in index1.html and submitted it to the remote warehouse. Submit, pull the remote warehouse (git fetch origin dev), rebase and merge. The command line output is as follows:

The difference between git merge and rebase

First move the HEAD pointer to the top of the current origin branch, and then apply all commits to the current branch. The branch structure (in a straight line) is as follows:

The difference between git merge and rebase

It can be seen that during rebase, the current branch will commit 191b8cd, 00e08ec and the following two submissions based on the common ancestor of 135b375 , a total of 4 submissions were withdrawn. Then move HEAD to commit 322ca9 and reapply the 4 commits to the branch.

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