git ls-files:如何识别新文件(添加,未提交)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2298047/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:52:53  来源:igfitidea点击:

git ls-files: howto identify new files (added, not committed)?

git

提问by tanascius

After I called git add <file>the command git statuswill show me something like:

在我调用git add <file>命令后,它git status会显示如下内容:

...
new file:    <file>

Somehow I can't manage it to get the same information by using ls-files, it (ls-files -tcin this case) will show me:

不知何故,我无法通过使用来管理它以获取相同的信息ls-files,它(ls-files -tc在这种情况下)会告诉我:

H <commited file>
H <other commited file>
H <file>

There seems no commandline switch to exist for new files. The file is reported as cached, which is ok, but how do I find out that it is not committed at this time?

新文件似乎不存在命令行开关。文件被报告为缓存,这是可以的,但是我如何发现它此时没有提交?

Is this possible with ls-filesor some similar command (where I do not have to parse a lot of output like in the case of git status)?

这是否可以使用ls-files或一些类似的命令(在这种情况下我不必像 那样解析大量输出git status)?

回答by Andrew Aylett

You want to use git diff --cached. With --name-onlyit'll list all the files you've changed in the index relative to HEAD. With --name-statusyou can get the status symbol too, with --diff-filteryou can specify which set of files you want to show ('A' for newly added files, for instance). Use -Mto turn on move detection and -Cfor copy detection if you want them.

您想使用git diff --cached. 随着--name-only它会列出所有的文件你已经相对于头部的指数变化。随着--name-status即可获得身份的象征也与--diff-filter您可以指定要显示哪些文件集(“A”为新添加的文件,例如)。使用-M开启移动侦测和-C如果你想让他们的拷贝检测。

For the strictest reading of what you wrote, git diff --cached --name-only --diff-filter=Awill list all the files you've added since HEAD which don't exist in HEAD.

为了最严格地阅读您所写的内容,git diff --cached --name-only --diff-filter=A将列出自 HEAD 以来您添加的所有文件,这些文件在 HEAD 中不存在。

回答by Mike Seplowitz

Clarification:This is a way to show the files that I intendto add. This is not what the OP was looking for, but I'll leave this post in case it's useful to others.

说明:这是一种显示我打算添加的文件的方法。这不是 OP 正在寻找的内容,但我会留下这篇文章,以防对其他人有用。

This seems to show only the files that I have added [to my working copy, not the index]but aren't matched by my standard ignore patterns:

这似乎只显示了我添加的文件[到我的工作副本,而不是索引],但与我的标准忽略模式不匹配:

 $ git ls-files --others --exclude-standard

Without --exclude-standard, it also shows files that are ignored when I run git status.

如果没有--exclude-standard,它还会显示我运行时被忽略的文件git status

回答by Yaro

I would like to see all the added and modified files, so the merge of
git diff --cached --name-only
+
git ls-files --modified --deleted
but without [1]+ Stopped ...in between.

我想查看所有添加和修改的文件,因此合并
git diff --cached --name-only
+
git ls-files --modified --deleted
[1]+ Stopped ...中间没有。

When I use git diff --cached --name-only && git ls-files --modified --deletedI receive:

当我使用时,git diff --cached --name-only && git ls-files --modified --deleted我收到:

content/blog/2020/05/artificial-intellect.json
content/blog/2020/05/artificial-intellect.pug

[1]+  Stopped                 git diff --cached --name-only
content/index.json
index.php