本文介绍了我可以将"git status"设置为“显示未跟踪文件的文件大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看未跟踪文件的文件大小对我来说非常方便.也许是已更改文件的旧/新大小.

It would be very handy for me to see the file size of untracked files. And maybe the old/new size of changed files.

是否可以通过配置git来显示它?

Is it possible to configure git in a way to show it?

推荐答案

不,您不能让git status那样做.

您可能不需要 进行git status操作,因为您可以编写自己的 own 命令来执行此操作.使用:

You may not need to make git status do that, because you can write your own command that does that instead. Use:

git -C "$(git rev-parse --show-cdup)" ls-files --other --exclude-standard

获取文件列表.然后,您可以使用所需的任何命令来查看有关这些文件的统计信息.您可能要在git status之后立即运行此命令,并让git status禁止使用--untracked-files=no列出自己的列表.例如:

to obtain the file list. You can then use whatever command you like to view statistics about those files. You may want to run this command immediately after git status and have git status suppress its own listing with --untracked-files=no. For instance:

alias st='git status -uno;
  git -C "$(git rev-parse --show-cdup)" ls-files --others --exclude-standard -z |
  xargs -0 ls -lR'

这里我也使用了-z,因为我正在使用的命令xargs -0 ls -l可以处理该问题,并将其表示为 shell 别名而不是 Git 别名.

Here I've used -z as well since the command I am using, xargs -0 ls -l, can handle that, and expressed this as a shell alias rather than a Git alias.

这里有一个缺陷.虽然git status-uall会枚举目录中所有未跟踪的文件,但git ls-files --others不会:就像默认的git status一样,通过仅打印包含目录的名称来汇总此类文件.此处的ls -l将显示目录中的文件;要停止此操作,请改用ls -ld,但是您当然看不到任何文件大小.

There is a flaw here. While git status with -uall will enumerate all the untracked files within a directory, git ls-files --others won't: it behaves like a default git status, summarizing such files by printing only the containing directory name. The ls -l here will show the files within the directory; to stop that, use ls -ld instead, but of course you won't see any file sizes.

(要获取修改的文件,请使用git ls-files -m而不是--others.)

(To get modified files, use git ls-files -m rather than --others.)

这篇关于我可以将"git status"设置为“显示未跟踪文件的文件大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-26 03:56
查看更多