62

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?

8 Answers 8

88

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
4
  • Save some typing with: hg revert -C filename.java
    – jbranchaud
    May 2, 2013 at 16:52
  • The -C shortcut was introduced with mercurial 2.0 see mercurial.selenic.com/wiki/WhatsNew
    – Fooman
    May 2, 2013 at 20:50
  • 8
    I'm not sure I understand how -C is short for --no-backup... is it a Courageous revert?
    – dreamlax
    Jun 4, 2013 at 5:12
  • 1
    I guess it stands for clean, since it has the same effect as calling hg revert FILE && hg clean. Dec 17, 2013 at 12:09
48

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

23

I find the purge extension handy. Usage:

hg purge

"This extension purges all files and directories not being tracked by Mercurial"

...including the .orig files but excluding ignored files (unless you use --all).

8

As other's have pointed out, you can safely delete these files.

You can remove them by executing this command from the root of your repo:

rm `hg st -un | grep orig`

If you want to revert, and don't care at all about backing up the original files, the command you want is:

hg update -C
6

Those are copies of the files from before you reverted them. If you don't need those, you can delete them, either by hand or by using the Purge extension:

hg clean
3
  • 1
    There is "clean" command in standard Mercurial -- perhaps you are thinking of the purge extension and hg purge? Mar 1, 2010 at 12:10
  • 1
    @Martin: Typing hg clean says that clean is provided by the purge extension
    – Casebash
    Sep 17, 2010 at 5:58
  • 2
    Casebash: ah, right -- the purge extension provides the command under both names: hg purge and hg clean. Sep 17, 2010 at 12:50
5

These backup files can be created for merge and revert operations (cf. man page). You can add an ignore rule if you want, or simply delete them if you don't need them anymore.

0

These are rather common, resulting from various operations. A glance at one of the moderate sized repositories I work on finds 237 of them. I don't like deleting things that may end up being useful, and I have no reason to name legitimate files with the same suffix, so I add the following to .hgignore instead:

.\.orig$
0

I made this batch file myself.

IF "%1%" == "d" (
    del /s *.orig
    del /s *.rej
 ) ELSE ( 
    del /s /p *.rej
    del /s /p *.orig
 )

Help: Save this content as orig.bat

  1. Run orig d to delete all rejects and orig files at once without confirmation
  2. Run orig to delete files with confirmation [Safety mechanism]

Hope this is helpful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.