如何找出要提交的文件的空间需求?
我要归档一个包含大量垃圾的旧大型项目。我希望我永远不再需要它,但我想将所有重要的事情置于版本控制之下。由于项目混乱,很难说出什么是来源以及什么可以消失(没有 makefile
,没有 make clean
,什么都没有)。 所以我想把几乎所有内容都放在那里,只考虑排除最大的文件。
如何列出要提交(或暂存)的文件及其大小?
我可以编写一个脚本或其他东西,但希望有一个更简单的解决方案。我在 Cygwin 下工作,唯一可用的 gui 是 git gui ,它不显示文件大小。否则它就非常适合我的需要。
I'm going to archive an old huge project containing a lot of garbage. I hope I'll never need it again, but I want to put all important things under version control. Because of the chaos in the project, it's not easy to say what are the sources and what can go away (there's no makefile
, no make clean
, nothing). So I'd like to put there nearly everything and consider only the largest files for exclusion.
How can I list the files to be committed (or to be staged) together with their size?
I could write a script or whatever, but hope for a simpler solution. I'm working under Cygwin and the only gui available is git gui
which doesn't show the file sizes. Otherwise it'd be perfect for what I need.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你可以试试这个。它找到所有大于 1M 的文件,并将它们从最大到最小排序。打印的文件大小以字节为单位:
输出:
更新:循环
find
返回的文件并打印其git
状态:You could try this. It finds all files larger than 1M and sorts them from largest to smallest. The file sizes printed are in bytes:
Output:
Updated: loop over the files returned by
find
and print theirgit
status:如果您已经添加了文件,则可以在 git 中使用命令
ls-files
。可以通过各种巧妙的方式传输输出以获得您所需要的内容。 https://git-scm.com/docs/git-ls-files我建议在第一个大 git add 之前设置一个 .gitignore 文件以通配符去掉任何明显的文件。
使用
-s
开关列出暂存项目,仅获取文件路径,然后使用 du 获取文件大小:从 du 中删除 human 会留下 kb 中的所有值。这允许使用排序,将最大的放在底部:
然后可以使用输出来删除大的文件
然后使用 git reset删除问题文件。
获取输出,您可以决定要删除的行(这可以做得更聪明,但只需获取尾部的行数,然后删除头部的总数)。
If you've already added the files, within git is the command
ls-files
. The output can be piped in various clever ways to get what you need. https://git-scm.com/docs/git-ls-filesI would suggest setting up a .gitignore file to wildcard out any obvious ones before the first big git add.
Using the
-s
switch to list the staged items, get just the file paths, and then uses du to get the file size:Removing human from du leaves all the values in kb. Which allows sort to be used, putting the largest at the bottom:
The output could then be used to remove large ones
To then remove problem files use the
git reset <file>
.Taking the output, you can decide the rows to remove (this could be done cleverer, but just took the number of rows with tail, and then removed the total with head).
初步估计,目录树顶部的
du -sk .
将为您提供所需的空间。在执行 git gc 后,它可能会被高估。但早在项目退役之前,您就应该使用版本控制。
To a first approximation,
du -sk .
at the top of the directory tree will give you the space needed. After you dogit gc
, it might be an overestimate.But you should have been using version control long before you reached the point of retiring the project.
我不了解 Git,但如果您使用 Mercurial,您可以组合使用:
I don't know about Git, but if you're using Mercurial, you could use a combination of: