lab 34 Rebasing
Goals
- Use the rebase command rather than the merge command.
Ok, we are back in time before the first merge and we want to get the changes in master into our greet branch.
This time we will use the rebase command instead of the merge command to bring in the changes from the master branch.
Execute:
git checkout greet git rebase master git hist
Output:
$ go greet Switched to branch 'greet' $ $ git rebase master First, rewinding head to replay your work on top of it... Applying: added Greeter class Applying: hello uses Greeter Applying: updated Rakefile $ $ git hist * 8db103d 2013-10-06 | Updated Rakefile (HEAD, greet) [Ismail Dhorat] * 30ae4be 2013-10-06 | Hello uses Greeter [Ismail Dhorat] * 8da6cc5 2013-10-06 | Added greeter class [Ismail Dhorat] * cad8e98 2013-10-06 | Added README (master) [Ismail Dhorat] * 27b8b27 2013-10-06 | Added a Rakefile. [Ismail Dhorat] * 23944f0 2013-10-06 | Moved hello.rb to lib [Ismail Dhorat] * 273edac 2013-10-06 | Add an author/email comment [Ismail Dhorat] * 9efd33e 2013-10-06 | Added a comment (v1) [Ismail Dhorat] * 8b9a1c6 2013-10-06 | Added a default value (v1-beta) [Ismail Dhorat] * f6f4d6b 2013-10-06 | Using ARGV [Ismail Dhorat] * f98d857 2013-10-06 | First Commit [Ismail Dhorat]
Merge VS Rebase 01
The final result of the rebase is very similar to the merge. The greet branch now contains all of its changes, as well as all the changes from the master branch. However, the commit tree is quite different. The commit tree for the greet branch has been rewritten so that the master branch is a part of the commit history. This leaves the chain of commits linear and much easier to read.
When to Rebase, When to Merge? 02
Don’t use rebase …
- If the branch is public and shared with others. Rewriting publicly shared branches will tend to screw up other members of the team.
- When the exact history of the commit branch is important (since rebase rewrites the commit history).
Given the above guidelines, I tend to use rebase for short-lived, local branches and merge for branches in the public repository.