branch - Help understanding the benefits of branching in Mercurial -
i've struggled understand how branching beneficial. can't push repo 2 heads, or 2 branches... why ever need/use them?
first of all, can push 2 heads, since don't want that, default behavior prevent doing it. can, however, force push go through.
now, branching, let's take simple scenario in non-distributed version control system, subversion.
let's assume have colleague working in same project you. current latest changeset in subversion repository revision 100, both update locally both of have same files.
ok, colleague has been working on changes couple of hours now, , commits. brings central repository revision 101. you're still on revision 100 locally, , you're still working on changes.
at point, complete, , want commit, subversion won't let you. says have update first, start update process.
the update process wants take changes, , pretend started revision 101 instead of 100. if changes not in conflict whatever colleague committed, hunky dory, if changes are in conflict, have problem.
now have merge changes changes, , things can go haywire. instance, might end merging 1 file ok, second file ok, or think, , third file, , discover you've got of details wrong, would've been better merge second file differently.
unless made backup of changes before updating, , sooner or later forget, have problem.
now, above scenario quite common. well, perhaps not merging part, depends on how many working in same area or files @ same time, "must update before committing" part quite common subversion.
so how mercurial it?
well, mercurial commits locally, doesn't talk remote repository @ all, won't stop committing.
so, let's try above scenario again, in mercurial time.
the tipmost changeset in remote repository revision 100. both have cloned down, , you're both starting work on changes, revision 100.
your colleague completes changes , commits, locally. pushes changeset central repository, bringing tip there revision 101.
you complete changes, , commit, locally, , want push, error message you've discovered, , asking about.
so how different?
well, changes committed, there no way, unless try hard accidentally lose them or destroy them.
here's 3 repositories in play , current state:
colleague ---98---99---100---a central ---98---99---100---a ---98---99---100---b
if push, , allowed (or force push through), central repository this:
central ---98---99---100---a \ +--b
two heads. if colleague pulled, 1 should continue working from? question reason mercurial default prevent causing this.
so instead pull, , above state in your own repository.
in other words, can chose impact own repository , create multiple heads there, you not imposing problem on else.
you merge, same type of operation had in subversion, except changeset safe, committed, , won't accidentally corrupt or destroy it. if, mid-merge, want start over, can, nothing lost, no harm done.
after merge, local repository looks this:
you ---98---99---100---a----m \ / +--b--+
this safe push, , if colleague pulls, knows has continue m changeset, 1 merged , changes.
the above description happens due mercurials distributed nature.
you can name branches, make them more permanent. instance, might want name branch "stable", signal changesets on branch have been thoroughly tested , safe release customers or put production. merge changes onto branch when said testing has been completed.
the nature, however, same above description. whenever more 1 person works on project mercurial, will branches, , that's thing.
Comments
Post a Comment