如何获取单个子文件夹的 git-status?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1044446/
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
How to get git-status of a single subfolder?
提问by EoghanM
When I do git status in a subfolder of my repository it includes the status of parent folders also.
当我在存储库的子文件夹中执行 git status 时,它也包括父文件夹的状态。
Is there a way to constrain git-status to just a particular folder?
有没有办法将 git-status 限制为特定文件夹?
回答by Matt Curtis
git status .
will show the status of the current directory and subdirectories.
将显示当前目录和子目录的状态。
For instance, given files (numbers) in this tree:
例如,给定这棵树中的文件(数字):
a/1
a/2
b/3
b/4
b/c/5
b/c/6
from subdirectory "b", git status
shows new files in the whole tree:
从子目录“b”,git status
显示整个树中的新文件:
% git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: ../a/1
# new file: ../a/2
# new file: 3
# new file: 4
# new file: c/5
# new file: c/6
#
but git status .
just shows files in "b" and below.
但git status .
只显示“b”及以下的文件。
% git status .
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached <file>..." to unstage)
#
# new file: 3
# new file: 4
# new file: c/5
# new file: c/6
#
Just this subdirectory, not below
只是这个子目录,而不是下面
git status .
shows all files below "b" recursively. To show just the files in the "b" but not below, you need to pass a list of just the files (and not directories) to git status
. This is a bit fiddly, depending on your shell.
git status .
递归显示“b”下面的所有文件。要仅显示“b”中的文件而不是下方的文件,您需要将仅包含文件(而不是目录)的列表传递给git status
. 这有点繁琐,具体取决于您的外壳。
Zsh
Zsh
In zsh you can select ordinary files with the "glob qualifier" (.)
. For example:
在 zsh 中,您可以选择带有 "glob qualifier" 的普通文件(.)
。例如:
% git status *(.)
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: 3
new file: 4
Bash
重击
Bash doesn't have glob qualifiers but you can use GNU find
to select ordinary files and then pass them along to git status
like so:
Bash 没有 glob 限定符,但您可以使用 GNUfind
选择普通文件,然后将它们传递给git status
像这样:
bash-3.2$ find . -type f -maxdepth 1 -exec git status {} +
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: 3
new file: 4
This uses -maxdepth
which is a GNU findextension. POSIX finddoesn't have -maxdepth
, but you can do this:
这种用途-maxdepth
这是一个GNU发现扩展。POSIX find没有-maxdepth
,但你可以这样做:
bash-3.2$ find . -path '*/*' -prune -type f -exec git status {} +
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: 3
new file: 4
回答by VonC
Some plumbing commands do take a directory as parameter:
一些管道命令确实将目录作为参数:
git ls-files -t -o -m aDirectory
would give you all files changed but not updated (not added to stage), or untracked. And that for a directory.
将为您提供所有已更改但未更新(未添加到舞台)或未跟踪的文件。那是一个目录。
As written in this thread, git ls-files does not support a '--added
option.
正如此线程中所写, git ls-files 不支持 '--added
选项。
more fundamental reason is because
ls-files
plumbing is about the index.
Added is notabout comparison between the index and the work tree.
It is between the HEAD commit and the index, and it does not belong to ls-files plumbing.
更根本的原因是因为
ls-files
水暖是关于指数的。
添加的不是索引和工作树之间的比较。
它位于 HEAD 提交和索引之间,不属于 ls-files 管道。
So, using commands mentioned here:
所以,使用这里提到的命令:
git diff-index --name-only -B -R -M -C HEAD src
would give you both non-added and added files
会给你非添加和添加的文件
git diff-files --name-only -B -R -M -C src
would give you only non-added files. (while detecting rewrites, renames, copies, ...)
只会给你未添加的文件。(同时检测重写、重命名、复制……)
As usual with plumbing commands, some scripting is in order ;)
像往常一样使用管道命令,一些脚本是有序的 ;)
回答by Marcus Griep
Imperfect, but this works as well from within the the directory you are interested in:
不完美,但这也适用于您感兴趣的目录:
git status | grep -v ' \.\./'
That will hide all directories that would require an upward reference in their relative path.
这将隐藏所有需要在其相对路径中向上引用的目录。
If you want to get color spitting out the other end, set color.status
to always
:
如果您想让另一端吐出颜色,请设置color.status
为always
:
git config color.status always
回答by Macarse
When I tried git, I didn't find a way to do that.
当我尝试 git 时,我没有找到一种方法来做到这一点。
I ended up doing:
我最终做了:
x@x:~/x$ git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# b
# main/a
nothing added to commit but untracked files present (use "git add" to track)
x@x:~/x$ git status | grep main
# main/a
回答by Ratna Halder
cd YOUR_REQUIRED_DIRECTORY , then,
git status .
cd YOUR_REQUIRED_DIRECTORY ,然后是
git status 。
回答by Jo?l Conraud
It is possible to restrict git status
to the current directory (without child folders) by giving a pathspec using the magic word glob
and *:
:
git status
通过使用魔术字glob
和给出路径规范,可以限制到当前目录(没有子文件夹)*:
:
git status ':(glob)*'