git ls-files:如何识别新文件(已添加,未提交)? [英] git ls-files: howto identify new files (added, not committed)?

查看:137
本文介绍了git ls-files:如何识别新文件(已添加,未提交)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

...
new file:    <file>

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

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

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?

这是可能的 ls-files 或者一些类似的命令(我不需要像 git status 那样解析很多输出)?

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

推荐答案

您想使用 git diff --cached 。使用 - 仅限名称它会列出您在索引中相对于HEAD所更改的所有文件。使用 - name-status ,您可以获得状态符号,使用 - diff-filter ,您可以指定哪个您想要显示的文件集(例如,新添加的文件为'A')。使用 -M 打开移动检测功能,如果需要,使用 -C 进行复印检测。

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

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

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

这篇关于git ls-files:如何识别新文件(已添加,未提交)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆