How to get mercurial to notice files added into subdirectories? (hg st, hg add)
Solution 1
Well, plain hg add
without any extra arguments adds files in sub-directories as well, it basically adds all files with status unknown to be tracked.
However, if you specify a simple mask, it only operates on your current working directory (ie. the working directory of the hg command, not the working directory associated with the repository), so if you're currently situated in the sub-directory, it will add those files, if you're in the root directory, it will add those files instead.
In other words, this:
hg add test*
Only operates on files in the directory you're currently situated.
You can override that behavior by specifying a mask that tells hg to operate on sub-directories:
hg add **/test*
This says "add all files that match 'test*' in the current directory and all sub-directories.
If you remove one of the asterixes, you only operate on sub-directories of the current working directory.
It would help if you posted what specific commands you executed, and the output, if any, and the output of hg st
before and after.
Solution 2
Did you hg init
in the subdirectory as well? If so, don't. Below illustrates the issue:
C:\>hg init project
C:\>cd project
C:\project>hg init sub
C:\project>echo >file1
C:\project>echo >sub\file2
C:\project>hg st
? file1
Delete the subfolder's .hg
directory to fix it:
C:\project>rd /s/q sub\.hg
C:\project>hg st
? file1
? sub\file2
Unlike Subversion, Mercurial only uses an .hg
directory at the root of a project.
Related videos on Youtube
GJ.
Updated on May 14, 2022Comments
-
GJ. about 2 years
If I add a new file into my project's root, it appears with a
?
status inhg st
, and gets added withhg add
.However, if I add a new file into a subdirectory, it doesn't appear in
hg st
at all, and only gets added if I explicitly add the file (not even if I add the file's containing directory).How can I get mercurial to notice files in subdirectories, in a similar way to how subversion notices them?
Thanks
-
GJ. over 13 yearsI'm not applying any mask. I just add a file in a subdir and do an
hg st
, and see no output (not even an unknown?
status for the file). If I do the same thing in the root directory, I do see the file with an unknown status. It's worthwhile to mention the subdir isn't in ignored in the .hgignore -
Lasse V. Karlsen over 13 yearsWhat is the name of the directory, and what is the name of the file, and can you post your .hgignore file, just in case?
-
Lasse V. Karlsen over 13 yearsOh, and check @Mark Tolonen's answer here as well, it might be that that's your problem.
-
GJ. over 13 yearsThanks Mark but no, I didn't
hg init
any subdir, and there's no.hg
directories other than in my root. Any other idea? -
Mark Tolonen over 13 yearsOnly idea is to post a complete example of the commands leading up to the problem. Do you have an .hgignore at all? Maybe something is accidently matching. What happens if, in a brand new directory, you
hg init
, make create a file, create a subdir, create a file in the subdir, andhg status
? That should show both files.