Basic use – Merge branches
Rebase is interpreted as a rebase and is used to merge changes into the current branch, similar to merge but more elegant in the merged gitGraph
Below is a screenshot from git’s official website to illustrate. Explain the presence of the trunk Master and development branch Topic in the sample
Git merge merge topic=>master merge topic=>master merge topic=>master merge topic=>master merge topic=>master
Next through the local actual operation record, do a comparison.
- Merge Merge operation
- Rebase merge operation
Dev /git-feature dev/git-feature dev/git-feature dev/git-feature
Before rebase:
After rebase is executed:
Rebase:
The result of Rebase is that there are almost no forks, and all merges are on just a few lines. Conflicts occur during rebase, which is different from merge. Merge conflicts need to be resolved once after merge. In rebase, however, merge conflicts need to be resolved one by one according to commit records. And git rebase –continue continue the merge. If you do not want to resolve a conflict, you can run Git rebase –skip the merge. To abort the merge, run git rebase –abort
Technical upgrade – Merge submission
Git rebase -i <commit-id> merge local commits
Commit four times locally
During the development process, there is an urgent need, and the code of the current branch needs to be committed temporarily. Occasionally, the code needs to be committed several times. Finally, when it needs to commit remotely, it will find that there is only one function module, but there are 7 or 8 commit timesgit rebase -i
If you enter interactive mode, you can see that there are all local COMMIT records. If you want to keep the last two, delete the other pick rows.:wq
Exit interactive mode, resolve conflicts one by one, and submit OK.
If the commit-id is not empty, the list of commits from the commit-id to the most recent is displayed
conclusion
Rebase provides a clearer record of commits than merge. Note: It is not recommended to perform the rebase operation on a common branch, because the rebase nature of rebase can cause confusion in the branch content