git rebase Tutorials

Source: Internet
Author: User
Tags commit garbage collection
Git rebase

Suppose you now create a branch called "MyWork" based on the remote branch "origin".

$ git Checkout-b mywork origin

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 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):

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 origin

These commands will cancel each commit (commit) in your "mywork" branch and temporarily save them as patches (patches), and then update the "mywork" branch to the newest "origin" branch, in the ". Git/rebase" directory. 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)

Now we can look at the difference between the history created by merging and using rebase:

In the process of 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

This 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--abort

Gitcast:c7-rebase


From:http://gitbook.liuhui998.com/4_2.html

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.