当我在存储库的子文件夹中执行git status时,它还包括父文件夹的状态。
有没有一种方法可以将git-status约束到特定文件夹?
当我在存储库的子文件夹中执行git status时,它还包括父文件夹的状态。
有没有一种方法可以将git-status约束到特定文件夹?
Answers:
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。这有点奇怪,具体取决于您的外壳。
在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没有glob限定符,但是您可以使用GNUfind选择普通文件,然后将它们传递给git statuslike:
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
这使用-maxdepth了GNU find扩展。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
.引用的当前文件夹感兴趣,而不对其子文件夹感兴趣,该怎么办。有什么解决办法吗?谢谢!
git status *(.)。Bash并不具有仅遍历文件的捷径,但是您可以使用扩展的findeg find . -type f -maxdepth 1 -exec git status {} +。似乎是您想要放入别名或脚本而不是一直输入的那种东西。
一些管道命令确实将目录作为参数:
git ls-files -t -o -m aDirectory
会为您提供所有已更改但未更新(未添加到阶段)或未跟踪的文件。还有一个目录。
如该线程中所述,git ls-files不支持'--added选项。
更根本的原因是因为
ls-files管道与指数有关。
添加的内容不是关于索引和工作树之间的比较。
它在HEAD提交和索引之间,并且不属于ls文件管道。
因此,使用此处提到的命令:
git diff-index --name-only -B -R -M -C HEAD src
会给你既未添加文件又添加了文件
git diff-files --name-only -B -R -M -C src
只会给您未添加的文件。(在检测重写,重命名,复制等时)
与管道命令一样,按顺序进行一些脚本编写;)
不完美,但是在您感兴趣的目录中也可以正常工作:
git status | grep -v ' \.\./'
这将隐藏所有需要在其相对路径中向上引用的目录。
如果要使另一端喷出颜色,请设置color.status为always:
git config color.status always
当我尝试git时,我没有找到一种方法来做。
我最终做了:
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