我如何绘制git repo的代码行历史记录? [英] How can I graph the Lines of Code history for git repo?

查看:227
本文介绍了我如何绘制git repo的代码行历史记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想在每次提交之后获得版本库中的代码行数。



我发现的唯一(非常糟糕的)方式是使用 git filter-branch 来运行 wc -l * ,以及运行 git的脚本在每次提交时重置--hard ,然后运行 wc -l <​​/ code>



它更清晰一些,当工具运行时,它会输出第一次提交的代码行,然后输出第二行代码等等。这是我想要的工具输出的内容(例如):

  me @ something: 〜/ $ gitsloc --branch master 
10
48
153
450
1734
1542

我已经使用了ruby的'git'库,但最近我发现使用 .lines() code>方法在一个差异,这似乎应该给予增加的行(但不:它会返回0,当你删除行例如)

  require'rubygems'
require'git'

total = 0
g = Git.open(working_dir =' / Users / dbr / Desktop / code_projects / tvdb_api')

last = nil
g.log.each do | cur |
diff = g.diff(last,cur)
total = total + diff.lines
puts total
last = cur
end


解决方案

您也可以考虑 gitstats ,它将这个图形生成为html文件。

Basically I want to get the number of lines-of-code in the repository after each commit.

The only (really crappy) ways I have found is to use git filter-branch to run wc -l *, and a script that runs git reset --hard on each commit, then runs wc -l

To make it a bit clearer, when the tool is run, it would output the lines of code of the very first commit, then the second and so on. This is what I want the tool to output (as an example):

me@something:~/$ gitsloc --branch master
10
48
153
450
1734
1542

I've played around with the ruby 'git' library, but the closest I found was using the .lines() method on a diff, which seems like it should give the added lines (but does not: it returns 0 when you delete lines for example)

require 'rubygems'
require 'git'

total = 0
g = Git.open(working_dir = '/Users/dbr/Desktop/code_projects/tvdb_api')    

last = nil
g.log.each do |cur|
  diff = g.diff(last, cur)
  total = total + diff.lines
  puts total
  last = cur
end

解决方案

You might also consider gitstats, which generates this graph as an html file.

这篇关于我如何绘制git repo的代码行历史记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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