简体   繁体   English

在当前目录中查找已签出代码的大小

[英]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文件与树中其他位置的文件之间没有硬链接,但这通常是正确的:

  • run du to get the total usage 运行du以获取总使用量
  • run du on .git itself to get the .git usage .git本身上运行du以获取.git用法
  • subtract the second number from the first number 从第一个数字中减去第二个数字

The second easy way is to install a version of du that does have --exclude . 第二种简单方法是安装确实具有--excludedu版本。

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.

相关问题 git从已签出的存储到分支 - git from checked-out stash to branch TeamCity:如何将未版本控制的配置文件放入已签出的存储库中? - TeamCity: How to put unversioned configuration files in a checked-out repository? 如何使签出的分支成为主分支 - How to make checked-out branch to become master 检查是否将提取分支并允许将其检出 - Check whether a branch will be fetched and allowed to be checked-out 使用git进行Web部署-如何仅在检出的实时站点中拥有大型二进制文件,而不是git repo中的blob - Web deployment with git - how to have large binaries only in checked-out live site, and not as blobs in git repo 存储在refs / head之外的ref是否可以被视为分支并签出并作为普通分支进行处理? - Can a ref stored outside refs/heads be considered a branch and checked-out and worked-on as a normal branch? 为什么Git允许推送到添加的工作树中的已签出分支? 我应该如何恢复? - Why does Git allow pushing to a checked-out branch in an added worktree? How shall I recover? 从检出的 Git 分支中找到“父”分支的可靠方法 - Reliable way of finding 'parent' branch from a checked-out Git branch 显示所有最近的 git 提交,无论它们是否属于本地签出分支 - Show all recent git commits, whether they belong to a locally checked-out branch or not 文档在哪里解释了为什么“git log” output 根据签出的分支而有所不同? - Where do docs explain why "git log" output differs based on checked-out branch?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM