How to use the command 'hg status' (with examples)

How to use the command 'hg status' (with examples)

Mercurial is a distributed version control system that allows users to track changes to their project files. The hg status command is used to show files that have changed in the working directory. It provides useful information about the status of files, such as whether they have been modified, added, removed, or deleted.

Use case 1: Display the status of changed files

Code:

hg status

Motivation: Sometimes, you may want to quickly check the status of all the files in your project to see if any of them have been modified. By running hg status, you can get a comprehensive overview of the changes in the working directory.

Explanation: The command hg status with no additional arguments will display the status of all files that have changed in the working directory. It will show whether each file has been modified, added, removed, or deleted.

Example output:

M file1.py
A file2.py
R file3.py
! file4.py

In this example output, file1.py has been modified, file2.py has been added, file3.py has been removed, and file4.py has been deleted.

Use case 2: Display only modified files

Code:

hg status --modified

Motivation: When working on a large project, it can be overwhelming to see the status of all files. By using the --modified argument with hg status, you can filter the output to only show files that have been modified, making it easier to focus on changes that you have made.

Explanation: The --modified argument restricts the output of hg status to only show files that have been modified in the working directory.

Example output:

M file1.py

In this example output, only file1.py has been modified.

Use case 3: Display only added files

Code:

hg status --added

Motivation: In some scenarios, you may want to see a list of files that have been added to the project. By using the --added argument with hg status, you can filter the output to only display files that have been added to the working directory.

Explanation: The --added argument restricts the output of hg status to only show files that have been added in the working directory.

Example output:

A file2.py

In this example output, only file2.py has been added.

Use case 4: Display only removed files

Code:

hg status --removed

Motivation: It can be useful to see a list of files that have been removed from the project. By using the --removed argument with hg status, you can filter the output to only show files that have been removed from the working directory.

Explanation: The --removed argument restricts the output of hg status to only show files that have been removed in the working directory.

Example output:

R file3.py

In this example output, only file3.py has been removed.

Use case 5: Display only deleted (but tracked) files

Code:

hg status --deleted

Motivation: There may be situations where you want to see a list of deleted (but still tracked) files in the project. By using the --deleted argument with hg status, you can filter the output to only display files that have been deleted, but are still tracked by Mercurial.

Explanation: The --deleted argument restricts the output of hg status to only show files that have been deleted, but are still known to Mercurial.

Example output:

! file4.py

In this example output, file4.py has been deleted, but is still tracked by Mercurial.

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

Code:

hg status --rev revision

Motivation: When working with multiple changesets, you may want to compare the changes in the working directory to a specific changeset. By using the --rev argument with hg status, you can specify a revision and see the changes made since that revision.

Explanation: The --rev argument followed by a revision number restricts the output of hg status to show the changes made in the working directory compared to the specified changeset.

Example output:

M file1.py
A file2.py

In this example output, file1.py has been modified and file2.py has been added since the specified changeset.

Use case 7: Display only files matching a specified glob pattern

Code:

hg status --include pattern

Motivation: In some cases, you may want to see the status of files that match a specific pattern. By using the --include argument with hg status, you can filter the output to only show files that match the specified glob pattern.

Explanation: The --include argument followed by a glob pattern restricts the output of hg status to only show files that match the specified pattern.

Example output:

M file1.py
A file2.py

In this example output, both file1.py and file2.py match the specified pattern.

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

Code:

hg status --exclude pattern

Motivation: There may be instances where you want to exclude certain files from the status output based on a glob pattern. By using the --exclude argument with hg status, you can filter the output to exclude files that match the specified pattern.

Explanation: The --exclude argument followed by a glob pattern excludes files from the output of hg status that match the specified pattern.

Example output:

M file1.py

In this example output, file1.py matches the glob pattern, while file2.py does not.

Conclusion:

The hg status command is a powerful tool in Mercurial that allows you to quickly check the status of files in your project. By using various arguments, such as --modified, --added, --removed, --deleted, --rev, --include, and --exclude, you can filter the output to suit your needs and focus on specific changes or groups of files.

Related Posts

How to use the command 'eix' (with examples)

How to use the command 'eix' (with examples)

The ’eix’ command is a utility for searching local Gentoo packages.

Read More
Using the Haxe Library Manager (haxelib) (with examples)

Using the Haxe Library Manager (haxelib) (with examples)

1: Searching for a Haxe library haxelib search keyword Motivation: When building a Haxe project, you often need to find and use external libraries to add functionality or improve development efficiency.

Read More
How to use the command nvm (with examples)

How to use the command nvm (with examples)

NVM is a command-line tool that allows you to easily install, uninstall, or switch between different versions of Node.

Read More