简体   繁体   English

如何计算 git 中未暂存的文件?

[英]How to count unstaged files in git?

I've found a way to count the staged files .我找到了一种计算暂存文件的方法 However, I'd like to get a count of the exact opposite, ie to learn how many files that are in the red.然而,我想得到一个完全相反的计数,即了解有多少文件是红色的。

When I execute git status , I see I deleted a bunch of file.当我执行git status时,我看到我删除了一堆文件。 However, I'd like to know how many that is.不过,我想知道有多少。 Then, I will go git reset in the same branch and check the number of tracked files (now in green, up to date).然后,我将 go git 在同一分支中重置并检查跟踪文件的数量(现在为绿色,最新)。 That way, I can learn how many junky files I had in my repo that wasn't tracked.这样,我可以了解我的仓库中有多少没有被跟踪的垃圾文件。

Surprisingly, googling how to count unstaged files gave no hits, so I wonder if I'm perhaps missing something very trivial at this ungodly early hour.令人惊讶的是,谷歌搜索如何计算未暂存的文件没有命中,所以我想知道在这个不敬虔的凌晨,我是否可能遗漏了一些非常微不足道的东西。

in git you can use the command在 git 你可以使用命令

git status -s -uno | wc -l

if you want to go with powershell use below code如果你想 go 和 powershell 使用下面的代码

git status -s -uno | Measure-Object -Line

please let me know if it helps you.如果对您有帮助,请告诉我。

The exact command to do this would be:执行此操作的确切命令是:

git ls-files --others --exclude-standard | wc -l

The --others option will include the untracked files. --others选项将包括未跟踪的文件。 --exclude-standard option will ignore the files ignored by .gitignore --exclude-standard选项将忽略.gitignore忽略的文件

Piping to wc -l will return a count of the output of ls-files管道到wc -l将返回ls-files的 output 的计数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM