[英]Find size of checked-out code in current directory
I want to find the size of the current checked-out files in a folder/project, but ignore the git directory. 我想在一个文件夹/项目中找到当前检出文件的大小,但是忽略git目录。
Something like: 就像是:
du . --ignore '.git'
Is there a way to find the size of all the files ignoring what's in the .git folder? 有没有一种方法可以查找所有文件的大小而忽略.git文件夹中的内容? When I do this:
当我这样做时:
du . --exclude='.git'
du . --exclude='./.git' # or this
Either way, I get: 无论哪种方式,我都会得到:
du: --exclude=./.git: No such file or directory
What do I do? 我该怎么办?
If your du
has no --exclude
option, you have two easy ways you can deal with this. 如果
du
没有--exclude
选项,则有两种简单的方法可以处理此问题。 This first one assumes that there are no hard-links between files in .git
and files elsewhere in the tree, but that's usually true: 第一个假设
.git
文件与树中其他位置的文件之间没有硬链接,但这通常是正确的:
du
to get the total usage du
以获取总使用量 du
on .git
itself to get the .git
usage .git
本身上运行du
以获取.git
用法 The second easy way is to install a version of du
that does have --exclude
. 第二种简单方法是安装确实具有
--exclude
的du
版本。
There is a third way to handle this, which is also pretty easy but a little tricky: just move .git
out of the way: 有第三种方法可以解决此问题,这也很容易,但也有些棘手:只需将
.git
移开即可:
mv .git ../save-git
du ...
mv ../save-git .git
If you use this method, make sure nothing is trying to do anything Git-like in between. 如果使用此方法,请确保在两者之间没有任何尝试做类似Git的操作。 Or, make
.git
a symbolic link to ../save-git
, or (if your Git is new enough) a plain-text file containing a redirect. 或者,使
.git
成为指向../save-git
的符号链接,或者(如果您的Git足够新的话)使之包含重定向的纯文本文件。 Both of those methods can mess with the total, but only by one disk-block worth of space (the symlink or plain-text direct takes a disk block, unless the OS / file-system uses in-inode symlinks and the symlink is short enough to fit in-inode). 这两种方法都可能造成总数混乱,但仅占用一个磁盘块空间(符号链接或纯文本直接占用一个磁盘块,除非OS /文件系统使用in-inode符号链接并且符号链接很短)足以容纳inode。
For whatever reason (likely the BSD history of the Mac's utilities), the macOS version of du
does not include --exclude
. 出于某种原因(可能是Mac实用程序的BSD历史记录),
du
的macOS版本不包含--exclude
。 However, at least as of 10.14.x, it does include the much-less-obviously-named -I
option which ignores items that are in the "mask" that is provided--in this case "mask" is just another name for some form of regular expression which at least takes simple *
and ?
但是,至少从10.14.x版本开始,它确实包含了名称很少的
-I
选项,该选项忽略了所提供的“掩码”中的项目-在这种情况下,“掩码”只是某种形式的正则表达式,至少需要简单的*
和?
wildcards. 通配符。
Running 跑步
du -I .git .
gives the size heirarchy, and 给出大小层次结构,并且
du -s -I .git .
gives the summary. 给出摘要。 In both cases, the
.git
directory is ignored. 在这两种情况下,都会忽略
.git
目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.