Git rebase Introduction

Source: Internet
Author: User

Original:
http://gitbook.liuhui998.com/4_2.html basic git rebase is used to merge changes from one branch to the current branch. Suppose you now create a branch called "MyWork" based on the remote branch "origin". $ git Checkout-b mywork origin assumes that the remote branch "origin" already has 2 commits,  now we make some changes in this branch and then generate two commits. $ 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 have made submissions. 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):  but if you want to make "mywork" Branching history looks like there's no merging, you might be able to git rebase:$ git checkout mywork$ git rebase origin These commands will cancel every commit in your "mywork" branch, and temporarily save them as patches (patches), which are placed in the ". Git/rebase" directory, and then update the "mywork" branch to the newest "origin" branch, and finally apply the saved patches to the "mywork" branch.   When the ' mywork ' branch is updated, it points to these newly created commits, and those older commits are discarded. If you run the Garbage collection command (pruning garbage collection), these discarded commits are deleted. (see git GC)   II. Conflict resolution during rebase, there may be conflicts (conflict). In this case, Git will stop rebase and will let you resolve the conflict, after resolving the conflict, use the "git-add" command to update the index of these content, then you do not need to execute git-commit, as long as the execution: $ git rebase  --continue so git will continue to apply the remaining patches. At any time, you can use the--abort parameter to endRebase, and the "MyWork" branch will return to the state of Rebase before the start of the operation. $ git rebase --abort The difference between git rebase and git merge now we can look at the difference between merge and the history of Rebase: When we use git log to see commit , the order of their commits is also different. Suppose C3 commits to 9:00AM,C5 submitted in 10:00AM,C4 submitted to 11:00AM,C6 submitted in 12:00am, the order in which to merge the observed commits using Git merge (from new to old) is: C7, C6,C4,C5,C3,C2, C1 the order in which to merge the observed commits using Git rebase (from new to old) is: C7, C6 ', C5 ',c4,c3,c2,c1  because C6 ' commits only C6 committed clones, C5 ' commits only C5 committed clones, From the user's point of view, the order of commits (from the new to the old) that was merged with Git rebase is: C7,c6,c5,c4,c3,c2,c1  In addition, when we use the git pull command, we can use the--rebase parameter, which is Git Pull--rebase, which means that each commit (commit) in your local current branch is canceled, and temporarily saved as patches (these patches are placed in the ". Git/rebase" directory), and then the local current branch is updated to the latest "origin "Branch, and finally apply the saved patches to the local current branch. For more information on Git pull, refer to git pull introduction      

Git rebase introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.