Mercurial workflows: mainline workflow
The simplified workflow
In the simplified workflow, it is nearly identical to the normal centralizedworkflows (except most operations are local). When I want to start work
for the day, I’ll:
- work work work
- hg commit –Am “Working on some stuff”
- work work work
- hg ci –Am “Working on some more stuff”
- work work work
- hg ci –Am “Finished my stuff”
Unlike the previous workflow, my “master” bookmark moves along, instead of always pointing at the latest pulled commit. It’s still important that this bookmark sticks around, as we’ll see soon. Now that I want to push, I want to first pull down incoming commits. Let’s suppose that someone else also made some commits on another repository and already pushed. The server repository shows this:
Note that we don’t see our bookmarks here, as by default bookmarks don’t get pushed upstream. When we pull from upstream, we’ll get the commit from the “otherdude” developer. So, I’ll:
- hg pull --rebase
This is what we expected, our commits that originally came after the “Finishing work on a feature” commit got moved AFTER the “otherdude” commit. This produces a nice clean timeline that makes localizing bugs and merging changes a lot easier. With a regular pull/merge workflow, you’re merging all 3 commits at once. With a rebase, I merge one commit at a time, making the potential merges much smaller. Each merge also modifies each commit, instead of one gigantic merge commit with all changes coming in at once.
Anyway, I’ve pull upstream changes, so now I’m ready to push:
- hg push –b master
Comparing rebase and merge
Just to show what a merge looks like in comparison, let’s say “otherdude” doesn’t rebase before he commits his additional work. He has some more commits:Now he wants to push these two commits up. However, the other user already pushed rebased commits, so now the server looks like:
Instead of doing a rebase on pull, he does a regular pull and update. Because other commits have gone in, he’ll need to do a merge:
- hg pull –u
- hg merge
- hg ci –Am “Stupid merge commit”
So the silly thing about this is the stupid merge commit contains ALL changes from the other two outgoing commits, yet all three commits get pushed! This also becomes really ugly over time, especially when you have overlapping commits and merges:
I’m not sure human beings are meant to comprehend this picture, so I’ll take the rebased workflow with its clean, linear history any day of the week. With the simplified workflow, rebasing is actually simpler than the pull/merge/commit workflow. Rebase is good, whether we work in topic branches or not.
source: mercurial-workflows-mainline-workflow
Use "pull --rebase" seems to be more neat than "pull/merge/update" approach, if the intermediate commits are not completed and make no sense for others to see the details of those changesets.
回覆刪除