git rebase or merge usage scenarios most popular explanation

What is rebase ?

git rebase you can actually understand it to be "re-set the baseline," your current branch to re-set the start point. This time you can know the difference between the current branch to branch you need to compare.
The principle is simple: rebase need to set your current baseline based on a branch of a branch, which is the current baseline branches begin to move back the timeline to the end face of the latest branch of the track, so your current branch is tracking the latest branch. The operations here are based on a transaction file, so you need not be afraid of failure among consistency will affect the file. In the middle of the process, you can cancel the transaction at any time rebase.

The official explanation: https://git-scm.com/book/zh/v2/Git- branch - rebase

git rebase and git merge what's the difference?

rebase will commit your current branch into a common branch of the final surface, so called rebase. Again if you pull from a common branch out as the branch.
Example: If you pull out a feature from the master branch, then you submitted several commit, this time it was just something he developed merged into master, this time to master a few more than you commit time to pull branches if this time you rebase develop, it would take you a few current commit, commit that person into the back of.

 

 

 

merge will your current public branch and commit merge together to form a new commit submit

 

 

 

note:
  • Do not use rebase branch in common
  • Corresponding to the same local and remote branch, rebase the preferentially used, instead merge
Throws question:

Why not to use public branch rebase?
Because the next release of these are new commit, so that others pull out from this branch of the public, both need to rebase, equivalent to rebase stuff you come in, it is a new commit

  • 1-2-3 is now a branch of state
  • This time from the original master, checkout out a prod branch
  • Then master submitted 4.5, prod submitted 6.7
  • This time the master branch state is 1-2-3-4-5, prod states to become 1-2-3-6-7
  • If rebase master, prod branch became a state on the prod 1-2-3-4-5-6-7
  • If Merge
    1-2-3-6-7-8
    ........ | 4-5 |
  • Will come out a 8, 8 of this submission is to come together to submit 4-5

merge and rebase really just not the same scene with
a more popular explanation wave.
For example rebase, you've been doing development branch, and then one day, you want to modify the main line close to your branch, do a integrated, this situation is better with rebase. submit your modifications are on the main line of the head
if the merge, merge on his head wore a sum of 8, if you want to roll back on you submit a branch is very troublesome , there is an important issue, rebase, then I had to pull out of a branch from 3, rebase after the expiry of, do not know I was pulled out from where my development branch
Likewise, if you are in the main branch with rebase, rebase modify other branches, if people want to see is not what the history of the main branch, he saw not a complete history lesson, this history has been tampered with you

Common commands

  • git rebase -I dev dev branch can be merged into the current branch
    here, "-i" refers to the interactive mode. That you can intervene in the process rebase this transaction, including setting commit message, commit to pause and so on.

  • git rebase -abort abandon a merger

  • Merge multiple commit operation:
    1 git rebase -i dev
    2 last modified several times to commit records pick Squash
    3 save and exit, pop modify files, modify commit record again to save and exit (to remove the extra change-id keep only one)
    4 the Add git.
    5 git rebase --continue

Guess you like

Origin www.cnblogs.com/boluopabo/p/11205326.html