Hg / Add All Unstaged Files Matching Pattern
Add All Unstaged Files Matching Pattern
Use hg add to stage all unstaged files matching a specific pattern for your commit.
hg add -I <pattern> hg add -I <pattern> #!/bin/bash
# Add All Unstaged Files Matching Pattern
hg add {{[-I|--include]}} {{pattern}} import subprocess
# Add All Unstaged Files Matching Pattern
# Make sure to replace <placeholders> with actual values
def run_command():
cmd = [
"hg",
"add",
"-I",
"<pattern>"
]
try:
print(f"Executing: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
except FileNotFoundError:
print("Error: hg not found. Please install it first.")
if __name__ == "__main__":
run_command() When To Use
Selectively stage files for a commit based on specific patterns or types.
Command Builder
Tune the command before you copy it
hg add -I <pattern> Terminal Output
Expected runtime feedback
adding file1.txt
adding file2.txt
adding file3.log Power User Variants
Optimized versions
hg add --include '*.txt' Stage all unstaged .txt files.
hg add -I '*.log' Stage all unstaged .log files.
Unix Pipeline
Shell combinations
hg add -I '*.py' Stage all unstaged Python files.
hg add -I 'src/*' Stage all unstaged files in the src directory.
Troubleshooting
Common pitfalls
No files matching the pattern found.
Solution: Check the pattern syntax and ensure files exist.
Command not found: hg.
Solution: Install Mercurial or check your PATH.
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
- Step 1
Open your terminal and navigate to your repository.
- Step 2
Run the command: hg add -I 'pattern' to stage matching files.
- Step 3
Verify staged files with hg status.
Alternative Approaches
Comparable commands in other tools
Alternative version control tools for the same job.
jj split -r <revision> -d <revset> Jj / Split Revision Insert Before After jj split -r <revision> -B <revset> -A <revset> Git / Copy Files Changed In Last Commit To Remote git scp <remote_name> HEAD~1 Git / Copy Specific Directory To Remote git scp <remote_name> <path/to/directory> Git / Create Git Repo Current Directory Commit All Files git setup