Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Revert and Update in Mercurial

I'm just getting started with Mercurial, and I've come across something which I don't understand.

I made changes to several files, and now I want to undo all the changes I made to one of them (i.e. go back to my last commit for one specific file).

As far as I can see, the command I want is revert.

In the page I linked to, there is the following statement:

This operation however does not change the parent revision of the working directory (or revisions in case of an uncommitted merge). To undo an uncomitted merge, you can use "hg update -C -r." which will reset the parents to the first parent.

I don't understand the difference between the two (hg revert vs. hg update -C -r). Can anyone enlighten me as to the difference? And in my case, do I really want the revert or the update to go get rid of the changes I made to the file?

like image 939
Edan Maor Avatar asked Mar 24 '10 10:03

Edan Maor


People also ask

What is hg revert?

hg revert changes the file content only and leaves the working copy parent revision alone.

How do I revert changes 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.

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 you Uncommit in Heartgold?

A simple way to 'uncommit' your last commit is to use hg strip -r -1 -k. In case the link breaks, the documentation mentioned by @phb states: hg rollback Roll back the last transaction (DANGEROUS) (DEPRECATED) Please use 'hg commit --amend' instead of rollback to correct mistakes in the last commit.


1 Answers

The first difference is revert can work on a subset of the working copy while update works on the whole working copy. the other difference is in what happens when you want to go back to a version other than the last committed one.

if we have revisions (caps are committed, lower case are changes in the working copy, parent revision is C )

A-B-C-d 

update -C -r B will give you

A-B-C 

with your working copy set to B, any changes will result in branching from B (parent revision set to B)

A-B-C   \e 

revert -r B will give you

A-B-C-b' 

where b' is a set of changes which undoes everything in the intermediate committed changes, in this case it undoes all of C. any changes now just join the b' set (parent revision left unchanged at C)

like image 120
jk. Avatar answered Sep 22 '22 10:09

jk.