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