tags:

views:

68

answers:

2

The short question is: if I hg rollback, how does Peter get my rolled back version if he cloned from me? What are the exact steps he or me has to do or type?

This is related to http://stackoverflow.com/questions/3034793/in-mercurial-when-peter-hg-clone-me-and-i-commit-and-he-pull-and-update-he-g

The details:

After the following steps, Mary has 7 and Peter has 11. My repository is 7 What are the exact steps Peter or me has to do or type SO THAT PETER GETS 7 back?

F:\>mkdir hgme

F:\>cd hgme

F:\hgme>hg init

F:\hgme>echo the code is 7 > code.txt

F:\hgme>hg add code.txt

F:\hgme>hg commit -m "this is version 1"

F:\hgme>cd ..

F:\>hg clone hgme hgpeter
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

F:\>cd hgpeter

F:\hgpeter>type code.txt
the code is 7

F:\hgpeter>cd ..

F:\>cd hgme

F:\hgme>notepad code.txt   [now i change 7 to 11]

F:\hgme>hg commit -m "this is version 2"

F:\hgme>cd ..

F:\>cd hgpeter

F:\hgpeter>hg pull
pulling from f:\hgme
searching for changes
adding changesets
adding manifests
adding file changes
added 1 changesets with 1 changes to 1 files
(run 'hg update' to get a working copy)

F:\hgpeter>hg update
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

F:\hgpeter>type code.txt
the code is 11


F:\hgpeter>cd ..

F:\>cd hgme

F:\hgme>hg rollback
rolling back last transaction

F:\hgme>cd ..

F:\>hg clone hgme hgmary
updating to branch default
1 files updated, 0 files merged, 0 files removed, 0 files unresolved

F:\>cd hgmary

F:\hgmary>type code.txt
the code is 7

F:\hgmary>cd ..

F:\>cd hgpeter

F:\hgpeter>hg pull
pulling from f:\hgme
searching for changes
no changes found

F:\hgpeter>hg update
0 files updated, 0 files merged, 0 files removed, 0 files unresolved

F:\hgpeter>type code.txt
the code is 11


F:\hgpeter>

What are the exact steps Peter or me has to do or type SO THAT PETER GETS 7 back? There should be some steps that Peter can do to get the "current state" of my repository since he cloned from me. I shouldn't need to knock on his front door to tell him, "hey, you need to rollback" or whatever.

+3  A: 

If someone has already pulled your changes (which is the case you're describing), a rollback isn't appropriate.

From hg manual:

This command is not intended for use on public repositories. Once changes are visible for pull by other users, rolling a transaction back locally is ineffective (someone else may already have pulled the changes). Furthermore, a race is possible with readers of the repository; for example an in-progress pull from the repository may fail if a rollback is performed.

What you should do is hg backout the changeset, then tell Peter to pull.

If you insist on rolling back, you could tell Peter to reclone the repository, but I wouldn't recommend working this way.

Idan K
it seems that I should have use "hg backout -r -1" -- which is to say, backout my previous version (cancel my previous commit)... and a new revision is created. So Peter, knowing it or not, when he does an "hg pull" and "hg update", will get the "backout" in any case. If he made changes and wants to commit and push, hg will tell him to pull and update first, which will also get the "backout".
動靜能量
You're correct. rollback is an undo, and you should have done backout, then peter would get that as part of his normal push/pull cycle
Ry4an
+2  A: 

Yes, this scenario of code change should never use hg rollback. It should use hg backout. hg rollback removes history, but if

1) someone pulled from you
2) or, you pushed

then your version is known to be "out in the wild" and some day can "come back to bite you" by adding back to your repository. So, the rule is, never use hg rollback, unless you are rollbacking something that should have never been in the repository, such as all the compiled object code files that make the repository history very big, and you are sure nobody pulled and you never pushed, then use hg rollback. For ordinary revision control use, use hg backout

hg backout tip

will backout the last revision in your repository (by creating a new changeset and history).

Reference: http://hgbook.red-bean.com/read/finding-and-fixing-mistakes.html
the section Dealing with committed changes

動靜能量