git status -> 显示将在子目录中添加(暂存)的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12682045/
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 14:42:51  来源:igfitidea点击:

git status -> Show files that will be added (staged) in subdirectories

gitversion-control

提问by Amelio Vazquez-Reina

Say I start a git repository in a folder, and I have several subdirectories in it.

假设我在一个文件夹中启动了一个 git 存储库,其中有几个子目录。

I have several globbing patterns .gitignoreto exclude files in the subdirectories. However, when I do git statusbefore I stage anything, git status only shows the names of the subfolders that will be added, without being specific about which files in each subdirectory will be added (staged) if I do git add ..

我有几个通配模式.gitignore来排除子目录中的文件。但是,当我git status暂存之前执行任何操作时, git status 仅显示将添加的子文件夹的名称,而没有具体说明如果我这样做,将添加(暂存)每个子目录中的哪些文件git add .

Interestingly though, git statusis explicit about the files that will be committedafter I stage files with git add ..

但有趣的是,git status是明确的关于将文件提交后我舞台文件git add .

Is there anyway to ask git statusto be explicit about files for the files that would be staged?

无论如何要要求git status明确有关将上演的文件的文件?

回答by Penghe Geng

Try:

尝试:

git status -u

or the long form:

或长格式:

git status --untracked-files

which will show individual files in untracked directories.

这将显示未跟踪目录中的单个文件。

Here's the detailed description of -uoption from git-status man page:

以下是git-status 手册页-u选项的详细说明:

enter image description here

在此处输入图片说明

回答by cweigel

You can simply use

你可以简单地使用

git add --dry-run .

in the root of your repository which gives you a list of any file in any sub directory that would be added while considering .gitignore.

在您的存储库的根目录中,它为您提供了在考虑.gitignore.

回答by jthill

git ls-files -o --exclude-standard

git ls-files -o --exclude-standard

Every path in your worktree that isn't staged (-o) and won't be ignored by git add(--exclude-standard).

工作树中未暂存 ( -o) 且不会被git add( --exclude-standard)忽略的每条路径。

回答by Adrian Cornish

How about putting a .gitignorefile in your sub directories instead along the line of

如何将.gitignore文件放在子目录中而不是沿着

# Ignore everything in this directory
*
# Except these file
!.gitignore
!file1
!file2
!file3

回答by Pradeep Pandey

use git command git ls-files -o to list untracked file

使用 git 命令 git ls-files -o 列出未跟踪的文件

instead -o use -c --cached Show cached files in the output (default)

相反 -o 使用 -c --cached 在输出中显示缓存文件(默认)

-d --deleted Show deleted files in the output

-d --deleted 在输出中显示已删除的文件

-m --modified Show modified files in the output

-m --modified 在输出中显示修改过的文件