using hg revert to revert a group of files in Mercurial
Asked Answered
A

3

7

I'm using Mercurial to read and debug a complex project, and my modify of the project can be divided into different group of files clearly. For example, if I modified four files

src1.cc src1.hh src2.cc src2.hh

It's apparent that I can divide them into two file groups such as group src1 includes src1.cc src1.hh and group src2 includes src2.cc src2.hh.

I'm wondering if I can revert a group of files by a simple command like 'hg revert group-name-alias' instead of listing all the filename of the group, which is a awful idea if I have modified many files?

Any help really appreciated!

Atheroma answered 27/3, 2012 at 3:24 Comment(1)
See #5907129Humidifier
G
5

From what I can understand of your use-case, you can:

  1. Use patterns in the hg revert command. This means that you can run hg revert src1* to revert all the first group.

    Most probably, though, your stuff is in sub-folders and thankfully you can specify a parent folder to the revert command.

    So say your files are really like: foo/src1.cc, foo/src1.hh, bar/src2.cc, bar/src2.hh. In that case, you can revert all the second group with hg revert bar, assuming you're in the top folder. If you're already in the bar folder, you can run hg revert ..

    You can specify several patterns.

  2. Use Mercurial queues if each one of your "file groups" is also a different unit of work (a different bug fix or feature). This is not so desirable if all files belong to the same unit of work, though.

Gay answered 27/3, 2012 at 21:4 Comment(0)
O
4

No. To the best of my knowledge, Mercurial has no mechanism for grouping files.

You could do some trickery with aliases ([alias] revert-group-name = revert src2.cc src2.hh in ~/.hgrc), but aliases can only be prefixes, and can't perform variable expansions.

If your files are simple enough, you could use shell globbing (hg revert src2*), or a shell variable (GROUP_NAME="src2.cc src2.hh", then hg revert $GROUP_NAME).

You could also consider writing a small Mercurial extension. If you know Python, they don't take very long (my first took me about 30 minutes).

Obduliaobdurate answered 27/3, 2012 at 3:38 Comment(0)
C
3

If the filenames meet patterns, you can use that pattern:

hg revert src1* 

or

hg revert src1*.*

If those files are in a specific directory, you can do this:

hg revert dir\*

If the directory is more than one level deep and you want to get that directory and all its subdirectories, you can use this version of that commend:

hg revert dir\**\*
Chard answered 7/12, 2016 at 15:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.