2017年8月23日 星期三

[GIT] Rebase

 GIT    rebase  


What is rebase


We can use rebase to copy the commits from other branch to another.
And after rebasing, we can merge and remove the source branch in order to get the clean single branch with all the commits.



Practice


Let’s create a new branch: NewBranch, and push a commit: New branch commit.
While there are a new commit: Master commit, on master.




Rebase

Now we will rebase NewBranch to master.

$ git rebase master NewBranch

Or

$ git checkout NewBranch
$ git rebase master



Resolve conflicts

During the rebase process, we may encounter several conflicts.
Notice that we have to resolve these conflicts for every commit in NewBranch.

Here are the three ways to deal with conflicts while rebasing.

1.  Skip this commit

$ git rebase --skip


2.  After resolving the conflict, continue rebasing

$ git rebase --continue


3.  Abort rebasing process

$ git rebase --abort



Merge

After resolving conflicts and continue the rebase process.
The git commit graph should be as following, the commit: “New branch commit” is on local





Let’s merge NewBranch to master for merging the commit history to master.

$ git checkout master
$ git merge NewBranch
$ git push


And delete the NewBranch for a clean commit history.
$ git push origin --delete NewBranch
$ git branch –d NewBranch

Which will result in the clean master.



Take a look at the git log of master.





Reference



沒有留言:

張貼留言