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?
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.
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).
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.
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.
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 :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With