当我在存储库的子文件夹中执行git状态时,它还包括父文件夹的状态。
有没有办法将git-status限制在特定的文件夹中?
发布于 2011-03-26 07:30:55
git status .将显示当前目录和子目录的状态。
例如,给定此树中的文件(编号):
a/1
a/2
b/3
b/4
b/c/5
b/c/6从子目录"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
#但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
#只有这个子目录,不在下面
git status .以递归方式显示"b“下的所有文件。要只显示"b“中的文件,而不是下面的文件,您需要将文件(而不是目录)的列表传递给git status。这有点麻烦,这取决于您的shell。
Zsh
在zsh中,您可以使用"glob限定符“(.)选择普通文件。例如:
% git status *(.)
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: 3
new file: 4Bash
Bash没有glob限定符,但是您可以使用GNU find来选择普通文件,然后将它们传递给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它使用GNU find扩展-maxdepth。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发布于 2020-02-20 18:53:18
通过使用神奇的单词glob和*:提供路径规范,可以将git status限制为当前目录(无子文件夹
git status ':(glob)*'发布于 2009-07-10 19:46:05
不完美,但在您感兴趣的目录中也能正常工作:
git status | grep -v ' \.\./'这将隐藏所有需要在其相对路径中向上引用的目录。
如果想让颜色从另一端吐出来,请将color.status设置为always
git config color.status alwayshttps://stackoverflow.com/questions/1044446
复制相似问题