简体   繁体   中英

using hg revert to revert a group of files in Mercurial

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!

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.

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).

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\**\*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM