如何查看git仓库中单个文件的文件大小历史记录? [英] How to see the file size history of a single file in a git repository?

查看:2004
本文介绍了如何查看git仓库中单个文件的文件大小历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在git仓库中查看文件的大小如何随时间变化?我想看看我的main.js文件(这是几个文件的组合和缩小)随着时间的推移而增长和缩小。 解决方案

您可以使用 git show --pretty = raw< commit> 的输出创建一个脚本来获取树,然后使用 git ls-tree -r -l <​​/ code>来获得你正在寻找的blob,包括文件大小。



如果你有ruby和安装了砂砾 gem,这里有一个我扔在一起的脚本:

  require'grit'

如果ARGV.size< 1
puts'usage:file-size FILE'
puts'从git仓库中运行'
exit
end

filename = ARGV [ 0] .to_s

repo = Grit :: Repo.new('。')
commits = repo.log('master',filename)
commits.each do |提交|
blob = commit.tree / filename
puts#{commit}#{blob.size} bytes
end

示例用法(脚本的文件名为file-size.rb)将向您显示somedir / somefile的历史记录:

  myproject $ ruby​​ file-size.rb somedir / somefile 


Is there anyway to see how a file's size has changed through time in a git repository? I want to see how my main.js file (which is the combination of several files and minified) has grown and shrunk over time.

解决方案

You could create a script that uses the output from git show --pretty=raw <commit> to obtain the tree, then uses git ls-tree -r -l to obtain the blob you are looking for, including the file size.

In case you have ruby and the grit gem installed, here's a little script I threw together:

require 'grit'

if ARGV.size < 1
  puts 'usage: file-size FILE'
  puts 'run from within the git repo root'
  exit
end

filename = ARGV[0].to_s

repo = Grit::Repo.new('.')
commits = repo.log('master', filename)
commits.each do |commit|
  blob = commit.tree/filename
  puts "#{commit} #{blob.size} bytes"
end

Example usage (filename of script is file-size.rb), will show you the history for somedir/somefile:

myproject$ ruby file-size.rb somedir/somefile

这篇关于如何查看git仓库中单个文件的文件大小历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆