Prevent "hg status" from showing everything under untracked directories
I find the output of hg status
too verbose for untracked directories. Suppose I have an empty repository that's managed by both git
and hg
. So there would be two di开发者_如何转开发rectories, .git
and .hg
.
The output of git status
is:
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .hg/
The output of hg status
is:
? .git/HEAD
? .git/config
? .git/description
? .git/hooks/applypatch-msg.sample
? .git/hooks/commit-msg.sample
? .git/hooks/post-commit.sample
? .git/hooks/post-receive.sample
? .git/hooks/post-update.sample
? .git/hooks/pre-applypatch.sample
? .git/hooks/pre-commit.sample
? .git/hooks/pre-rebase.sample
? .git/hooks/prepare-commit-msg.sample
? .git/hooks/update.sample
? .git/info/exclude
Is there a way to reduce its output to something like the following line?
? .git/
This works for me :
hg status -q
Option
-q
/--quiet
hides untracked (unknown and ignored) files unless explicitly requested with-u
/--unknown
or-i
/--ignored
.
You can just add in your .hgignore
file
syntax:glob
.git
.gitattributes
.gitignore
To ignore .git
entirely, and other git-related files.
If the goal is to only limit to a directory, you can still use .hgignore
if you add an hidden file in that directory (after this answer):
syntax:regexp
^.git/(?!\.hidden).+$
Since Mercurial do not track directories at all, that will ignore all files within .git
except the hidden one, effectively displaying only one line in the status.
You would also have the option -q/--quiet
(to hg status
), which hides untracked (unknown and ignored) files unless explicitly requested with -u/--unknown
or -i/--ignored
.
But that means .git
would not even show up in that case.
But if the goal is to limit in general the output of hg status to only the directories and not their content for untracked files, then I believe this is not possible:
- git track content of files and since no content is added, it only mentions the top directory has "having no content added"
- mercurial tracks files (not directories), hence the comprehensive list (of files).
I understand the question is about how to reduce the output: I had similar need but did not want to untrack or ignore files. If you are using *NIX, you cloud use grep, and you just want to reduce the output as your question states, for example to get rid of these lines:
hg status | grep -v "^\?\s\.git"
Or for example not showing removed files
hg status | grep -v "^R"
In Windows PowerShell an equivalent would be:
hg status | Select-String -Pattern ("^[^R]")
精彩评论