Original:Http://gitbook.liuhui998.com/4_2.htmlfirst, the basicgit rebase is used to merge changes from one branch into the current branch. Suppose you now create a branch called "MyWork" based on the remote branch "origin". $ git Checkout-b mywork originAssumeremote Branch "origin"There have been 2 commits,Now let's make some changes in this branch and then generate two commits (commit).$ VI file.txt$ git commit$ VI otherfile.txt$ git commit...but at the same time, some people have made some changes to the "origin" branch and made the submission. This means that the two branches of origin and mywork each "go forward" and "fork" between them.
here, you can use the "pull" command to drop the changes on the "origin" branch and merge with your changes; The result looks like a new "merged commit" (merge commit):However, if you want the "mywork" branching history to look like it has not been merged, you might be able to use Git rebase:$ git checkout mywork$ git rebase originThese commands will cancel each commit (commit) in your "mywork" branch and temporarily save them as patches (patches) to the ". Git/rebase" directory, and then update the "mywork" branch to the newest "origin" branch. Finally, the saved patches are applied to the "MyWork" branch.when the ' mywork ' branch is updated, it points to these newly created commits, and those old commits are discarded. If you run the Garbage collection command (pruning garbage collection), these discarded commits are deleted. (see git GC) Ii. Settlement of conflictsin therebase, there may be conflicts (conflict). In this case, Git will stop the rebase and will let you resolve the conflict, after resolving the conflict, use "Git-add"The command goes to update the index of these content, and then you do not need to perform git-commit as long as the execution:$ git rebase--continueThis way git will continue to apply the remaining patches. At any time, you can use the--abort parameter to terminate the action of Rebase, and the "MyWork" branch will return to the state before the start of rebase.$ git rebase--abortiii. The difference betweengit rebase and git merge now we can take a look at the merge (Merge) and withrebaseThe difference between the history of the Generation:when we use git log to see Commit, the order of the commits is different. Suppose C3 submitted to 9:00AM,C5 submitted at 10:00AM,C4 submitted to 11:00am,c6 submitted in 12:00am,for usinggit mergeThe order in which to merge the observed commits (from new to old) is:C7,C6,C4,C5,C3, C2,c1for usinggit rebaseThe order in which to merge the observed commits (from new to old) is:C7,C6 ', C5 ', C4,C3,C2,C1because C6 ' commits just C6 commits the clone, C5 ' commits only C5 commits the clone,use from the user's point of viewgit rebaseThe order in which the commits are seen after merging (from new to old) is:C7,c6,c5,C4,C3, C2,c1also, when using the git pull command, we can use the--rebase parameter, git pull--rebase, whererepresentsCancel each commit (commit) in your local current branch and save them temporarily as patches (these patches are placed in the ". Git/rebase" directory) andLocal CurrentBranch is updated to the newest "origin" branch, and finally the saved patches are applied to theLocal Currenton the branch. about thefor more information on Git pull, refer to theGit Pull Introduction"
git git rebase using