Using hg revert to return a group of files in Mercurial

I use Mercurial to read and debug a complex project, and my project change can be divided into different file groups. For example, if I changed four files

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

Apparently, I can split them into two file groups, such as the src1 group, including 'src1.cc src1.hh', and the src2 group includes 'src2.cc src2.hh'.

I am wondering if I can return a group of files with a simple command, for example, โ€œhg revert group-name-aliasโ€ instead of listing all the file names of the group, which is a terrible idea if I modified many files.

Any help really appreciated!

+4
source share
3 answers

Not. As far as I know, Mercurial has no mechanism for grouping files.

You can do some cheats with aliases ( [alias] revert-group-name = revert src2.cc src2.hh in ~/.hgrc ), but aliases can only be prefixes and cannot decompose variables.

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

You might also consider writing a small Mercurial extension. If you know Python, they do not take much time (my first took me about 30 minutes).

+4
source

From what I can understand from your use case, you can:

  • Use templates in the hg revert command. This means that you can do hg revert src1* to return the entire first group.

    Most likely, your material is located in subfolders and, fortunately, you can specify the parent folder for the revert command.

    So your files are really similar: foo/src1.cc , foo/src1.hh , bar/src2.cc , bar/src2.hh In this case, you can return the entire second group with hg revert bar , assuming you are in the top folder. If you are already in the bar folder, you can run hg revert . .

    You can specify several patterns.

  • Use Mercurial queues if each of your " filegroups " is also a different unit of work (another bug fix or function). It is therefore not desirable that all files belong to the same unit of work.

+4
source

If the file names match the patterns, you can use this pattern:

 hg revert src1* 

or

 hg revert src1*.* 

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

 hg revert dir\* 

If the directory is at a depth of more than one level, and you want to get this directory and all its subdirectories, you can use this version of this:

 hg revert dir\**\* 
+1
source

Source: https://habr.com/ru/post/1403581/


All Articles