How to list all files in a repository in Mercurial (hg)?
Asked Answered
B

5

76

Is there a command in mercurial that will list all files currently under source control?

I can do a dir /s to list all files in my folder and subfolders, but I have no idea which have been added to my repository. I have a variety of excluded file types and folders and I want verify that none of them were added before I set them up in my .hgignore file.

Brayer answered 8/6, 2010 at 18:20 Comment(1)
You should have a look at this post : mercurial.808500.n3.nabble.com/…Broddie
P
72

hg status --all will list all the files in the tree, with a letter indicating its status: M for modified, C for clean (owned by hg), and I for ignored.

For just ignored files, use hg status -i. For just files that will be added on the next commit, use hg status -a. These show only what you need to know and don't require scanning a long file list.

Phospholipide answered 8/6, 2010 at 18:24 Comment(4)
Since others might look here for information, I thought I’d mention my new hglist extension that gives Mercurial an "ls" command: alastairs-place.net/projects/hglistIrrigate
hg st -A is the abbreviated version of the above-mentioned command.Oulman
Great answer, but it doesn't directly answer the question. With a clean working state, hg status -c lists all tracked files and only tracked files. With other changes, hg status -carmd will do the trick. Add -n to exclude the status flag.Buyse
this answer isn't right as hg st --all will list all untracked files as well (with a preceding ?)Stubble
D
66

You might also check out the hg locate command. I use it, along with the -I option when I want to limit the files to a certain directory.

To list all files in your repository:

hg locate

From the repository ("root") directory:

hg locate -I dir/sub_dir/dir_of_interest

The path passed to -I needs to change depending on the directory in which you run the command. If you run the command from the dir directory in the example above, you'd need to modify your argument to locate:

hg locate -I sub_dir/dir_of_interest

The list of output files will remain the same, showing each file's full path in the repository.

Try hg help -v locate for more info.

Doug answered 18/8, 2010 at 16:40 Comment(5)
Just what I needed, thanks. This is a better answer for someone who just needs to list tracked files.Sesquiplane
hg loc is the abbreviated version of the above-mentioned command.Oulman
This is the real answer. Ned's answer is a non-starter.Connor
If you really want to use hg locate like this, you can automatically get the current directory with: hg locate -I `pwd`.Handstand
@NeilTraft I can't share your enthusiasm for using hg locate like this. hg status -i will list just files that are being ignored. hg status -a will list just those that will be added by a commit. With hg locate there is a considerable risk of user error in reconciling the list you see with the list that you expect. Where hg locate is amazingly useful is searching in any / all revisions for particular file names. Similarly hg grep will search all file content over any / all revisions as well.Handstand
L
23

hg manifest will list only the files in the repository, while hg status --all will list all the files in the repository's structure and include a marker for which are being tracked and which aren't.

Lenna answered 8/6, 2010 at 18:23 Comment(1)
This gives me exactly what I wanted, despite having the slight disadvantage that it can't be narrowed by folder like the OP wanted. It's still better than the accepted answer.Connor
H
3

Listing Only Ignored Or Added Files

To list only the ignored files, do: hg status -i.

For just added files, do hg status -a.

If you don't like typing much, you can shorten these to hg sta -i and hg sta -a.

This two uses of status are more simple than locate and will give you the specific files states that you are concerned about, so it is significantly less error prone.

More about hg status

To list all files in a mercurial repo do: hg status --all.

The files will be given a prefix before them when they are listed:

  M = modified
  A = added
  R = removed
  C = clean
  ! = missing (deleted by non-hg command, but still tracked)
  ? = not tracked
  I = ignored

If you want to list only the files in a folder, you can provide a path:

  • hg st --all MyFolder – all files in MyFolder
  • hg sta -i MyFolder – just ignored files in MyFolder.

As well as the -i for "Ignored" and -a for "Added", other flags are available to list only the files having a particular status.

Getting help

Read the other very useful answer here for a comprehensive explanation of the status command. It has down votes because the author has tried to show that you can discover all of the above by asking Mercurial about the status command like this:

hg help status

You can ask Mercurial to tell you about any of it's commands like this. And if you want a list of Mercurial's commands, then type hg help.

Handstand answered 9/10, 2014 at 14:40 Comment(0)
C
-6
C:\>hg help -v status
hg status [OPTION]... [FILE]...

aliases: st

show changed files in the working directory

    Show status of files in the repository. If names are given, only files
    that match are shown. Files that are clean or ignored or the source of a
    copy/move operation, are not listed unless -c/--clean, -i/--ignored,
    -C/--copies or -A/--all are given. Unless options described with "show
    only ..." are given, the options -mardu are used.

    Option -q/--quiet hides untracked (unknown and ignored) files unless
    explicitly requested with -u/--unknown or -i/--ignored.

    NOTE: status may appear to disagree with diff if permissions have changed
    or a merge has occurred. The standard diff format does not report
    permission changes and diff only reports changes relative to one merge
    parent.

    If one revision is given, it is used as the base revision. If two
    revisions are given, the differences between them are shown. The --change
    option can also be used as a shortcut to list the changed files of a
    revision from its first parent.

    The codes used to show the status of files are:

      M = modified
      A = added
      R = removed
      C = clean
      ! = missing (deleted by non-hg command, but still tracked)
      ? = not tracked
      I = ignored
        = origin of the previous file listed as A (added)

options:

 -A --all             show status of all files
 -m --modified        show only modified files
 -a --added           show only added files
 -r --removed         show only removed files
 -d --deleted         show only deleted (but tracked) files
 -c --clean           show only files without changes
 -u --unknown         show only unknown (not tracked) files
 -i --ignored         show only ignored files
 -n --no-status       hide status prefix
 -C --copies          show source of copied files
 -0 --print0          end filenames with NUL, for use with xargs
    --rev             show difference from revision
    --change          list the changed files of a revision
 -I --include         include names matching the given patterns
 -X --exclude         exclude names matching the given patterns

global options:
 -R --repository      repository root directory or name of overlay bundle file
    --cwd             change working directory
 -y --noninteractive  do not prompt, assume 'yes' for any required answers
 -q --quiet           suppress output
 -v --verbose         enable additional output
    --config          set/override config option (use 'section.name=value')
    --debug           enable debugging output
    --debugger        start debugger
    --encoding        set the charset encoding (default: cp1252)
    --encodingmode    set the charset encoding mode (default: strict)
    --traceback       always print a traceback on exception
    --time            time how long the command takes
    --profile         print command execution profile
    --version         output version information and exit
 -h --help            display help and exit
Crosson answered 8/6, 2010 at 18:25 Comment(5)
Funny how my answer keeps getting downvoted year after year. But is it really that bad to tell people to read the manual? Did stackoverflow invalidate documentation? Have people stopped using --help//?/man and other documentation because it's quicker to ask on stackoverflow than to read? I refuse to remove my answer :)Crosson
Heh, well, you can have a vote up for me, as this is the most useful answer here. I'll not write another one based on what I've discovered from it and see if I get any upvotes :-)Handstand
For what it's worth, your answer is great. But a user needs to know that status, as one of the hg commands will actually do this in the first place. I use Mercurial every day and I didn't know it could be asked to show ignored files.Handstand
@simendsjo: StackOverflow is not about repasting docs. Your "answer" is a wall of text, and the important piece (--all) isn't even on screen (you have to scroll to see it); and nowhere do you actually give the actual verbiage to accomplish the goal. Overall, not very helpful. For comparison, Benjohn gives the desired command first, and then offers explanation.Vibrio
This is not an answer. RTFM isn't what SO is about. We need to presume that they've already tried reading the manual or that they don't know where in the manual to look.Scarlatina

© 2022 - 2024 — McMap. All rights reserved.