Git, find out which files have had the most commits

前端 未结 4 364
耶瑟儿~
耶瑟儿~ 2021-01-30 14:29

How can I search my git logs to see which files have had the most activity?

4条回答
  •  春和景丽
    2021-01-30 15:03

    Here's a python script that you can pipe the log --numstat output through to get the results:

    import sys, re
    
    res = {}
    
    while 1:
        line = sys.stdin.readline()
        if len(line) == 0:
            break;
        m =  re.match("([0-9]+)[ \t]+([0-9]+)[ \t]+(.*)", line)
        if m != None:
            f = m.group(3)
            if f not in res: res[f] = {'add':0, 'rem':0, 'commits':0} 
            res[f]['commits'] += 1
            res[f]['add'] += int(m.group(1))
            res[f]['rem'] += int(m.group(2))
    
    for f in res:
        r = res[f]
        print "%s %s %s %s"%(r['commits'], r['add'], r['rem'], f)
    

    You can modify it as needed to sort/filter how you want.

提交回复
热议问题