Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a special file filter for mercurial revert command?

Tags:

mercurial

I need to revert all files in a working directory that match the name "test" anywhere inside the filename.

Is it possible to revert all this 3 files by using hg revert -I syntax:

  • /includes/atest.txt
  • /test.txt
  • /test/test/test.txt
like image 258
johnlemon Avatar asked Sep 19 '11 13:09

johnlemon


People also ask

How do I revert a file in Mercurial?

To revert a file to a specific changeset, use hg revert -r CHANGESET FILENAME . This will revert the file without committing it.

What is hg status?

hg status shows the status of a repository. Files are stored in a project's working directory (which users see), and the local repository (where committed snapshots are permanently recorded). hg add tells Mercurial to track files. hg commit creates a snapshot of the changes to 1 or more files in the local repository.


2 Answers

It should work (I cannot test it right now) with the following syntax, according to issue 1697:

Windows:

hg revert "glob:*test.*"
# or
hg revert -I "*test.*" --all

Unix:

hg revert 'glob:*test.*'
hg revert -I '*test.*'

(Note the simple quotes for Unix)

As noted by Blaise in the comments

On macOS/Unix, you need to use ** if you want to match files in any directory, e.g.

hg revert -I '**/*test.*' 
like image 178
VonC Avatar answered Oct 04 '22 15:10

VonC


To expand on the given answer above

You can include all files in subdirectories in your revert by using the following syntax:

Windows:

hg revert "glob:**\*test.*"

And I assume Unix would be:

hg revert 'glob:**/*test.*'
like image 26
ctrlplusb Avatar answered Oct 04 '22 13:10

ctrlplusb