Git - list all authors of a folder of files?

后端 未结 3 1189
梦毁少年i
梦毁少年i 2021-02-03 23:11

How can I list the author names of a particular folder that\'s versioned by git?

I see that I can git blame a file and list the author of each line, but I c

相关标签:
3条回答
  • 2021-02-03 23:40

    Actually, there is a native Git command for that, git shortlog:

    git shortlog -n -s -- myfolder
    

    will give a list of contributors that created commits that touched myfolder. By omitting option -s, the summary even lists the commit message summaries per author. Option -n sorts the authors by number of commits (from most to least) instead of alphabetical.

    And just in case you have not encountered a loose -- in a git command yet: it is a separator option to mark that what follows cannot be a <revspec> (range of commits), but only a <pathspec> (file and folder names). That means: if you would omit the -- and by accident had a branch or tag named myfolder, the command git shortlog -n -s myfolder would not filter for the directory myfolder, but instead filter for history of branch or tag "myfolder". This separator is therefore useful (and necessary) in a number of git commands, like log or checkout, whenever you want to be clear whether what you specify is either a revision (commmit, branch, tag) or a path (folder or file name). An of course, this site already has a question on this.

    0 讨论(0)
  • 2021-02-03 23:40

    If you want only the list of authors of a repository:

    git ls-files | xargs -n1 git blame --line-porcelain | sed -n 's/^author //p' | sort -d | uniq

    If you want to do it for a file order by the number of lines of code contributions it is simple:

    git blame --line-porcelain "_MY_FILE_" | sed -n 's/author //p' | sort | uniq -c | sort -rn

    If you want to do it for the whole repository also ordered by code contributions:

    git ls-files | xargs -n1 git blame --line-porcelain | sed -n 's/^author //p' | sort -f | uniq -ic | sort -nr

    0 讨论(0)
  • 2021-02-03 23:44

    Based on The shortest possible output from git log containing author and date

    do this

    git log --pretty=format:"%an%x09" myfolder | sort | uniq
    
    0 讨论(0)
提交回复
热议问题