如何查看git仓库中单个文件的文件大小历史记录? [英] How to see the file size history of a single file in a git repository?
问题描述
您可以使用 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屋!