Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Mercurial update and backout

Tags:

mercurial

What`s the difference between this 2 commands (i want to rollback to revision 1):

hg update -r 1
hg backout -r 1 --merge

(in the example tip revision is 3)

like image 802
f0b0s Avatar asked Jul 18 '09 23:07

f0b0s


People also ask

What is backout in mercurial?

Backout works by applying a changeset that's the opposite of the changeset to be backed out. That new changeset is committed to the repository, and eventually merged.

What does hg update do?

Use the command hg update to switch to an existing branch. Use hg commit --close-branch to mark this branch head as closed.

How do I revert a changeset in Mercurial?

Revert changes already committed To backout a specific changeset use hg backout -r CHANGESET . This will prompt you directly with a request for the commit message to use in the backout. To revert a file to a specific changeset, use hg revert -r CHANGESET FILENAME . This will revert the file without committing it.

How do you undo a pull in mercurial?

There is only one level of rollback, and there is no way to undo a rollback. It will also restore the dirstate at the time of the last transaction, losing any dirstate changes since that time. This command does not alter the working directory.


1 Answers

To start with, update -r 1 will undo revisions 2 and 3 in your working directory, whereas backout -r 1 --merge will undo revision 1, while keeping revisions 2 and 3. But there's a more fundamental difference:

update checks out an older revision in your working directory, whereas backout creates a new one (but normally you'd commit after the merge above). Try running glog after each of those to look at the revision graph:

before:

0 - 1 - 2 - @3

after revert:

0 - @1 - 2 - 3

after backout --merge; commit

0 - 1 - 2 - 3 - @5
     \- 4 - - - /

Because revert only affects the working directory, it is invisible to any user that clones your repository. They will end up at 3 before and after revert. Whereas after backout, they will end up at 5, which does not have the changes done by 1.

like image 175
brendan Avatar answered Nov 15 '22 12:11

brendan