Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are my changes gone after "hg revert"?

Tags:

mercurial

After my last commit I wrote a bunch of code. Before committing again, I ran hg add. It added some files I was not interested in, so I ran

$ hg revert --all

thinking that all the added files would go away. They did go away, but I also reverted all the code written since the last commit, which means a ton of work was lost! What are my options?

like image 933
Rahul Avatar asked Dec 19 '11 11:12

Rahul


People also ask

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 undo hg revert?

Just move them back on top of the original, using either a command prompt move command, or your systems file manager. I think what BandGap was asking, is if hg provides a command to restore the backup (without any commandline-fu or manual copying).

How do I undo 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 revert a pushed commit in Heartgold?

hg rollback reverts the last transaction, so you'd be left with unfinished merge, which you have to use hg update -C to get out. If you don't want *b (you have it in another clone), then enable the built-in MQ extension and run hg strip -r <*b> . It will get rid of *b and *merge.


1 Answers

When you hg revert a file (or --all files), Mercurial saves a backup of the file under another name. This is to make it harder for you to lose work. If the file was called foo, you will have a foo.orig with the original version.

You can use

$ hg status --all --include "**.orig"

to see all the .orig files in your working copy. Move the ones you need back, re-add them and commit.

On a related note: people sometimes add the --no-backup flag to their [defaults] section in order to get rid of the .orig files Mercurial scatter around. I think this a really bad idea... just ignore the .orig files instead by adding

syntax: glob
*.orig

to your .hgignore file. That's much safer and one day you'll be happy that you have these .orig file lying around :-)

like image 76
Martin Geisler Avatar answered Oct 20 '22 15:10

Martin Geisler