(window.webpackJsonp=window.webpackJsonp||[]).push([[1131],{1539:function(t,e,a){"use strict";a.r(e);var s=a(31),r=Object(s.a)({},(function(){var t=this,e=t.$createElement,a=t._self._c||e;return a("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[a("h1",{attrs:{id:"git-statistics"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#git-statistics"}},[t._v("#")]),t._v(" Git statistics")]),t._v(" "),a("h2",{attrs:{id:"lines-of-code-per-developer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#lines-of-code-per-developer"}},[t._v("#")]),t._v(" Lines of code per developer")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git ls-tree -r HEAD | sed -Ee "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v("'s/^.{53}//'")]),t._v(" | \\\nwhile read filename; do file "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"$filename"')]),t._v("; done | \\\ngrep -E "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v("': .*text'")]),t._v(" | sed -E -e "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v("'s/: .*//'")]),t._v(" | \\\nwhile read filename; do git blame --line-porcelain "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"$filename"')]),t._v("; done | \\\nsed -n "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v("'s/^author //p'")]),t._v(" | \\\nsort | uniq -c | sort -rn\n\n")])])]),a("h2",{attrs:{id:"listing-each-branch-and-its-last-revision-s-date"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#listing-each-branch-and-its-last-revision-s-date"}},[t._v("#")]),t._v(" Listing each branch and its last revision's date")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("for k in `git branch -a | sed s/^..//`; do echo -e `git log -1 --pretty=format:"),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%Cgreen%ci %Cblue%cr%Creset"')]),t._v(" $k --`\\\\t"),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"$k"')]),t._v(";done | sort\n\n")])])]),a("h2",{attrs:{id:"commits-per-developer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#commits-per-developer"}},[t._v("#")]),t._v(" Commits per developer")]),t._v(" "),a("p",[t._v("Git "),a("code",[t._v("shortlog")]),t._v(" is used to summarize the git log outputs and group the commits by author.")]),t._v(" "),a("p",[t._v("By default, all commit messages are shown but argument "),a("code",[t._v("--summary")]),t._v(" or "),a("code",[t._v("-s")]),t._v(" skips the messages and gives a list of authors with their total number of commits.")]),t._v(" "),a("p",[a("code",[t._v("--numbered")]),t._v(" or "),a("code",[t._v("-n")]),t._v(" changes the ordering from alphabetical (by author ascending) to number of commits descending.")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git shortlog -sn #Names and Number of commits\n\ngit shortlog -sne #Names along with their email ids and the Number of commits\n\n")])])]),a("p",[t._v("or")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git log --pretty=format:%ae \\\n| gawk -- "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v("'{ ++c[$0]; } END { for(cc in c) printf \"%5d %s\\n\",c[cc],cc; }'")]),t._v("\n\n")])])]),a("p",[a("strong",[t._v("Note:")]),t._v(" Commits by the same person may not be grouped together where their name and/or email address has been spelled differently. For example "),a("code",[t._v("John Doe")]),t._v(" and "),a("code",[t._v("Johnny Doe")]),t._v(" will appear separately in the list. To resolve this, refer to the "),a("code",[t._v(".mailmap")]),t._v(" feature.")]),t._v(" "),a("h2",{attrs:{id:"commits-per-date"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#commits-per-date"}},[t._v("#")]),t._v(" Commits per date")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git log --pretty=format:"),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%ai"')]),t._v(" | awk "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v("'{print \" : \"$1}'")]),t._v(" | sort -r | uniq -c\n\n")])])]),a("h2",{attrs:{id:"total-number-of-commits-in-a-branch"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#total-number-of-commits-in-a-branch"}},[t._v("#")]),t._v(" Total number of commits in a branch")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git log --pretty=oneline |wc -l\n\n")])])]),a("h2",{attrs:{id:"list-all-commits-in-pretty-format"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#list-all-commits-in-pretty-format"}},[t._v("#")]),t._v(" List all commits in pretty format")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git log --pretty=format:"),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('"%Cgreen%ci %Cblue%cn %Cgreen%cr%Creset %s"')]),t._v("\n\n")])])]),a("p",[t._v("This will give a nice overview of all commits (1 per line) with date, user and commit message.")]),t._v(" "),a("p",[t._v("The "),a("code",[t._v("--pretty")]),t._v(" option has many placeholders, each starting with "),a("code",[t._v("%")]),t._v(". All options can be found "),a("a",{attrs:{href:"https://git-scm.com/docs/pretty-formats",target:"_blank",rel:"noopener noreferrer"}},[t._v("here "),a("OutboundLink")],1)]),t._v(" "),a("h2",{attrs:{id:"find-all-local-git-repositories-on-computer"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#find-all-local-git-repositories-on-computer"}},[t._v("#")]),t._v(" Find All Local Git Repositories on Computer")]),t._v(" "),a("p",[t._v("To list all the git repository locations on your you can run the following")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("find $HOME -type d -name "),a("span",{pre:!0,attrs:{class:"token string"}},[t._v('".git"')]),t._v("\n\n")])])]),a("p",[t._v("Assuming you have "),a("code",[t._v("locate")]),t._v(", this should be much faster:")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("locate .git |grep git$\n\n")])])]),a("p",[t._v("If you have "),a("code",[t._v("gnu locate")]),t._v(" or "),a("code",[t._v("mlocate")]),t._v(", this will select only the git dirs:")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("locate -ber \\\\.git$\n\n")])])]),a("h2",{attrs:{id:"show-the-total-number-of-commits-per-author"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#show-the-total-number-of-commits-per-author"}},[t._v("#")]),t._v(" Show the total number of commits per author")]),t._v(" "),a("p",[t._v("In order to get the total number of commits that each developer or contributor has made on a repository, you can simply use the "),a("code",[t._v("git shortlog")]),t._v(":")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git shortlog -s\n\n")])])]),a("p",[t._v("which provides the author names and number of commits by each one.")]),t._v(" "),a("p",[t._v("Additionally, if you want to have the results calculated on all branches, add "),a("code",[t._v("--all")]),t._v(" flag to the command:")]),t._v(" "),a("div",{staticClass:"language-git extra-class"},[a("pre",{pre:!0,attrs:{class:"language-git"}},[a("code",[t._v("git shortlog -s --all\n\n")])])]),a("h4",{attrs:{id:"syntax"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#syntax"}},[t._v("#")]),t._v(" Syntax")]),t._v(" "),a("ul",[a("li",[t._v("git log ["),a("options",[t._v("]["),a("revision",{attrs:{range:""}},[t._v("] [[--] "),a("path",[t._v("]")])])],1)],1),t._v(" "),a("li",[t._v("git log --pretty=short | git shortlog ["),a("options",[t._v("]")])],1),t._v(" "),a("li",[t._v("git shortlog ["),a("options",[t._v("]["),a("revision",{attrs:{range:""}},[t._v("] [[--] "),a("path",[t._v("]")])])],1)],1)]),t._v(" "),a("h4",{attrs:{id:"parameters"}},[a("a",{staticClass:"header-anchor",attrs:{href:"#parameters"}},[t._v("#")]),t._v(" Parameters")]),t._v(" "),a("table",[a("thead",[a("tr",[a("th",[t._v("Parameter")]),t._v(" "),a("th",[t._v("Details")])])]),t._v(" "),a("tbody",[a("tr",[a("td",[a("code",[t._v("-n")]),t._v(", "),a("code",[t._v("--numbered")])]),t._v(" "),a("td",[t._v("Sort output according to the number of commits per author instead of alphabetic order")])]),t._v(" "),a("tr",[a("td",[a("code",[t._v("-s")]),t._v(", "),a("code",[t._v("--summary")])]),t._v(" "),a("td",[t._v("Only provide a commit count summary")])]),t._v(" "),a("tr",[a("td",[a("code",[t._v("-e")]),t._v(", "),a("code",[t._v("--email")])]),t._v(" "),a("td",[t._v("Show the email address of each author")])]),t._v(" "),a("tr",[a("td",[a("code",[t._v("--format")]),t._v("[="),a("format",[t._v("]")])],1),t._v(" "),a("td",[t._v("Instead of the commit subject, use some other information to describe each commit. "),a("format",[t._v(" can be any string accepted by the "),a("code",[t._v("--format")]),t._v(" option of "),a("code",[t._v("git log")]),t._v(".")])],1)]),t._v(" "),a("tr",[a("td",[a("code",[t._v("-w")]),t._v("["),a("width",[t._v("[,"),a("indent1",[t._v("[,"),a("indent2",[t._v("]]]")])],1)],1)],1),t._v(" "),a("td",[t._v("Linewrap the output by wrapping each line at "),a("code",[t._v("width")]),t._v(". The first line of each entry is indented by "),a("code",[t._v("indent1")]),t._v(" number of spaces, and subsequent lines are indented by "),a("code",[t._v("indent2")]),t._v(" spaces.")])]),t._v(" "),a("tr",[a("td",[a("revision",{attrs:{range:""}})],1),t._v(" "),a("td",[t._v("Show only commits in the specified revision range. Default to the whole history until the current commit.")])]),t._v(" "),a("tr",[a("td",[t._v("["),a("code",[t._v("--")]),t._v("] "),a("path")]),t._v(" "),a("td",[t._v("Show only commits that explain how the files matching "),a("code",[t._v("path")]),t._v(' came to be. Paths may need to be prefixed with "-- " to separate them from options or the revision range.')])])])])])}),[],!1,null,null,null);e.default=r.exports}}]);