“hg status” Command Examples

hg status is a command in Mercurial (Hg) that allows users to quickly view the status of files in their working directory. Here’s a detailed explanation of hg status:

  • Overview: When working with version-controlled files in a Mercurial repository, it’s essential to track changes made to files in the working directory. hg status provides a convenient way to check the status of files, indicating which files have been modified, added, removed, or are untracked.
  • Command Usage: To use hg status, users simply run the command within their Mercurial repository. When executed, hg status scans the working directory and displays a list of files along with their status indicators.
  • Status Indicators: The output of hg status includes status indicators that denote the state of each file. Common status indicators include:
    • M: Indicates that the file has been modified since the last commit.
    • A: Indicates that the file has been added to the repository but not yet committed.
    • R: Indicates that the file has been removed from the repository but still exists in the working directory.
    • !: Indicates that the file is missing from the working directory.
    • ?: Indicates that the file is untracked and not yet added to the repository.
  • Use Cases: hg status is valuable for quickly assessing the state of the working directory before committing changes. It helps users identify which files have been modified or added, ensuring that they include all relevant changes in their next commit.
  • Documentation Reference: The Mercurial documentation provides detailed information about hg status, including a list of status indicators and examples of command usage. Users can refer to this documentation for further guidance on interpreting the output of hg status and incorporating it into their workflow effectively.

“hg status” Command Examples

1. Display the status of changed files:

# hg status

2. Display only modified files:

# hg status --modified

3. Display only added files:

# hg status --added

4. Display only removed files:

# hg status --removed

5. Display only deleted (but tracked) files:

# hg status --deleted

6. Display changes in the working directory compared to a specified changeset:

# hg status --rev [revision]

7. Display only files matching a specified glob pattern:

# hg status --include [pattern]

8. Display files, excluding those that match a specified glob pattern:

# hg status --exclude [pattern]

Summary

In summary, hg status is a fundamental command in Mercurial that provides users with insight into the state of files in their working directory. By displaying status indicators for each file, it helps users track changes and ensure that their repository is in the desired state before committing modifications.

Related Post