The difference between git merge and git rebase and examples of Git branch creation and merging

There are two ways to create and merge branches in Git: git merge and git rebase.

git merge: merge the two branches into a new commit, and the new commit has 2 parents.

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

For specific differences, please refer to the summary of git merge and git rebase

Following the previous example:

git merge

  Specific operations: bob modifies twice in index1.html and submits it to the remote repository; lilei modifies twice in index.html and submits it to the remote repository; bob pulls the remote repository (git fetch origin dev) and merges it. The branch structure is as follows:

   

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

git rebase

  Specific operations: lilei modifies twice in index.html and submits it to the remote repository; bob modifies twice in index1.html and submits, pulls the remote repository (git fetch origin dev), and rebase merges. The command line output is as follows:

  

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

  

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

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325445886&siteId=291194637