hg Verified current stable Not installed? Version Control

Hg / Remove Staged Files Matching Pattern

Remove Staged Files Matching Pattern

Easily remove staged files matching a specific pattern from your Mercurial repository.

$
Terminal
hg remove -I <pattern>

When To Use

Removing unwanted staged files before committing changes.

Warning

Destructive operation. Confirm the target path and keep a backup before executing.

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
removing 'file1.txt'
removing 'file2.log'
removing 'file3.md'

Power User Variants

Optimized versions

hg remove --include '*.log'

Remove all staged log files.

hg remove -I '*.txt'

Remove all staged text files.

Unix Pipeline

Shell combinations

hg remove -I '*.tmp'

Remove all staged temporary files.

hg remove --include '*.md'

Remove all staged markdown files.

Troubleshooting

Common pitfalls

No files match the specified pattern.

Solution: Check the pattern syntax and ensure files exist.

Files are not staged for removal.

Solution: Use `hg add` to stage files before removing.

Command Breakdown

What each part is doing

hg
Base Command
The executable that performs this operation. Here it runs Hg before the shell applies any redirect operators.
-I
I| include
The value supplied for I| include.
<pattern>
pattern
The value supplied for pattern.
-I
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Run `hg remove -I pattern` to specify files to remove.

  2. Step 2

    Confirm the removal by checking the status with `hg status`.

  3. Step 3

    Commit the changes with `hg commit -m 'Removed specific files'`.

Alternative Approaches

Comparable commands in other tools

Alternative version control tools for the same job.