防止“汞状态”显示未跟踪目录下的所有内容

发布于 2024-08-26 14:29:15 字数 808 浏览 7 评论 0原文

我发现对于未跟踪的目录,hg status 的输出过于冗长。假设我有一个由 git 和 hg 管理的空存储库。所以会有两个目录,.git.hg

git status 的输出是:

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .hg/

hg status 的输出是:

? .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

有没有办法将其输出减少到类似以下行的内容?

? .git/

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 directories, .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/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

桃气十足 2024-09-02 14:29:16

这对我有用:

hg status -q

选项-q/--quiet隐藏未跟踪(未知和忽略)的文件,除非使用-u/-明确请求-未知-i/--忽略

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.

落花浅忆 2024-09-02 14:29:16

您只需在 .hgignore 文件中添加

 syntax:glob
.git
.gitattributes
.gitignore

即可完全忽略 .git 以及其他与 git 相关的文件。

如果目标只是限制到一个目录,如果您在该目录中添加隐藏文件(在 这个答案):

 syntax:regexp
 ^.git/(?!\.hidden).+$

由于 Mercurial 根本不跟踪目录,因此将忽略 中的所有文件。 git 除了隐藏的,实际上只显示状态中的一行。

您还可以选择 -q/--quiet (到 hg status),该选项隐藏未跟踪(未知和忽略)的文件,除非使用 -u 明确请求/--未知-i/--忽略
但这意味着在这种情况下 .git 甚至不会出现。


但是,如果目标是将 hg status 的输出限制为仅目录而不是未跟踪文件的内容,那么我相信这是不可能的:

  • git track content of files 并且因为没有内容添加后,它仅提到顶级目录具有“未添加内容”的
  • Mercurial 跟踪文件(而不是目录),因此是(文件)的完整列表。

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).
独夜无伴 2024-09-02 14:29:16

我知道问题是如何减少输出:我有类似的需求,但不想取消跟踪或忽略文件。如果您使用的是 *NIX,您可以使用 grep,并且您只想减少问题所述的输出,例如删除这些行:

hg status | grep -v "^\?\s\.git" 

或者例如不显示已删除的文件

hg status | grep -v "^R"

在 Windows PowerShell 中,等效项是:

hg status | Select-String -Pattern ("^[^R]")

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]")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文