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

26,833

Solution 1

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.

Solution 2

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.

Solution 3

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.

Solution 4

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.

Share:
26,833
JamesWampler
Author by

JamesWampler

I'm James Wampler and I am a Lead Software Developer in Seattle, Washington. I have an interest in .NET, full stack web development and Agile

Updated on July 05, 2022

Comments

  • JamesWampler
    JamesWampler almost 2 years

    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.

  • Gringo Suave
    Gringo Suave over 13 years
    Just what I needed, thanks. This is a better answer for someone who just needs to list tracked files.
  • al45tair
    al45tair over 11 years
    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/hglist
  • Serge Stroobandt
    Serge Stroobandt about 11 years
    hg st -A is the abbreviated version of the above-mentioned command.
  • Serge Stroobandt
    Serge Stroobandt about 11 years
    hg loc is the abbreviated version of the above-mentioned command.
  • Neil Traft
    Neil Traft over 10 years
    This is the real answer. Ned's answer is a non-starter.
  • Neil Traft
    Neil Traft over 10 years
    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.
  • simendsjo
    simendsjo over 10 years
    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 :)
  • undefined
    undefined over 10 years
    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.
  • Benjohn
    Benjohn over 9 years
    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 :-)
  • Benjohn
    Benjohn over 9 years
    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.
  • Ethan Furman
    Ethan Furman almost 9 years
    @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.
  • Benjohn
    Benjohn over 8 years
    If you really want to use hg locate like this, you can automatically get the current directory with: hg locate -I `pwd`.
  • Benjohn
    Benjohn over 8 years
    @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.
  • bph
    bph over 8 years
    this answer isn't right as hg st --all will list all untracked files as well (with a preceding ?)
  • cwallenpoole
    cwallenpoole over 3 years
    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.