Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using hg revert in Mercurial

Tags:

mercurial

I'm using Mercurial. I made a clone of a repository. For debugging, I changed a few lines of code in a java file. I did not commit those changes though. I just want to revert them back to their original state, as found in the repository. I tried hg revert filename.java, which did revert it, but now when I do hg status, I see additional files added in my folder now like:

? filename.java.orig 

Can I just delete those files, and why does Mercurial make them when I use revert?

like image 677
user246114 Avatar asked Feb 10 '10 18:02

user246114


People also ask

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 revert do?

hg revert changes the file content only and leaves the working copy parent revision alone. You typically use hg revert when you decide that you don't want to keep the uncommited changes you've made to a file in your working copy.

How do I revert my hg add?

hg revert -r . ^ path-to-file will revert the commit from the commit-set. then commit and submit (if using jelly fish) and you'll see the files removed from the changeset.

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.


2 Answers

You can also use the flag --no-backup and the .orig files will not be created

hg revert --no-backup filename.java 

As of Mercurial 2.0, you can instead use the flag -C to supress the .orig files from being created

hg revert -C filename.java 
like image 186
Fooman Avatar answered Oct 17 '22 14:10

Fooman


Yes, you can delete them. It's a safety feature in case you reverted something you didn't mean to revert.

like image 28
Hank Gay Avatar answered Oct 17 '22 15:10

Hank Gay