[Git] The difference between git merge and git rebase

git rebase

  • Principle: First extract all changes of the current branch from the switch branch to the latest commit, apply the dev branch to the latest branch, and delete the branch's commit content
  • Implementation process:
  1. The initial state is as follows, with two branches, one master and one develop. At this time, HEAD is at (6.added hello.txt file). Now execute git rebase develop
  2. Before git rebase
    Insert picture description here
  3. After git rebase
    Insert picture description here
  4. Summary : After the content of the newly created branch is merged into the latest submission of the master, and applied, all the submissions of the branch are deleted.

go merge

  • Principle: merge two branches and generate a new commit
  • Implementation process:
  1. Assuming that the HEAD of git is at 6.added hello.txt file, the latest commit of the master branch, execute git merge develop at this time, and the results are as follows:
    Insert picture description here
  2. Merge process : Git will automatically find the node of the new dev branch from the master branch (the common starting point for cutting branches). At this time, merge, git will identify the latest commit on the master and dev branches, and the identified changes will form a new one Submit, as 7. Merge branch'develop'
  3. Summary : Merge is to identify all changes in the starting and ending points of the branch and the main branch that are requested to be merged, and generate a new commit

Guess you like

Origin blog.csdn.net/m0_46537958/article/details/108383713