Recently, the head of the department came up with a very practical way to calculate the performance of each employee – that is, to count the workload of each developer. So the question is, workload is a very virtual thing, how to measure it? Specifically divided into three parts:

  • Specific work content
  • Lines of code
  • Time to get work done

Well, it’s easy to say, except for this line of code, how do we count this?

Some said to use Eclipse statistics, there are also said to use other editors to statistics, we have eight immortals across the sea of their own skills. Here’s my solution.

problems

All project source code is uploaded to remote Git repositories, such as GitLab, Github, etc.

From the initialization of a project to every code commit for a project, there are detailed records in each project’s.git directory.

Git! Git!

To solve the problem

Search on the net the git code statistics related command set https://segmentfault.com/a/1190000002434755 found it was a real article.

There are mainly the following command sets

Count the number of code submissions for a project participant, including additions, deletions, and final differences

git log –author=”$(git config –get user.name)” –pretty=tformat: –numstat | gawk ‘{ add += $1 ; subs += $2 ; loc += $1 – $2 } END { printf “added lines: %s removed lines : %s total lines: %s\n”,add,subs,loc }’ –

Git config –get user.name = $(git config –get user.name

Note: Don’t panic if the command is running on a machine other than Linux and you may get an error that gawk does not exist.

Error solution:

  • 1, Install Homebrew (users who have installed Homebrew please automatically skip)

    You can refer to the official website

  • 2. Install the GNU command line tool

    • First install the GUN Coreutils

    brew install coreutils

    • Next, you can install the software you want (if some packages fail to install, please try to execute firstbrew tap homebrew/dupes)
    brew install binutils brew install diffutils brew install ed --default-names brew install findutils --with-default-names  brew install gawk brew install gnu-indent --with-default-names brew install gnu-sed --with-default-names brew install gnu-tar --with-default-names brew install gnu-which --with-default-names brew install gnutls brew install grep --with-default-names brew install gzip brew install screen brew install watch brew install wdiff --with-gettext brew install wgetCopy the code

    We lack the gawk package here, so brew install gawk can be done from the command line.

    The — default-names option prevents Homebrew from pre-adding gs to newly installed commands so that we can use them by default, overwriting OS X pre-installed commands.

If you run the preceding command again, no error will be reported.

The result I performed in one of the projects was Added Lines: 11626 Removed Lines: 2722 Total lines: 8904

gitThe surrounding

Warehouse submitters rank by user name (currently the top 5 is viewed, the number can be set arbitrarily, to view all rankings, remove the head channel)

git log –pretty=’%aN’ | sort | uniq -c | sort -k1 -n -r | head -n 5

The warehouse submissioner is ranked by mailbox (it is operated according to the actual situation, one person may have more than one mailbox, currently it is the top 5, the number can be set freely, if you want to view all the rankings, you can remove the head channel)

git log –pretty=format:%ae | gawk — ‘{ ++c[$0]; } END { for(cc in c) printf “%5d %s\n”,c[cc],cc; }’ | sort -u -n -r | head -n 5

Contributor statistics

git log –pretty=’%aN’ | sort -u | wc -l

Submission statistics

git log –oneline | wc -l

git logParameter Description: --author specifies the author. --stat Displays the list of file changes for each commit. --shortstat specifies the number of lines changed for each commit. No list of files --numstat counts the number of lines changed per commit, including additions, deletions, and lists of files. -p displays the difference between each commit, and -2 displays only the last two updates (git)log-p-2) --name-only displays the list of modified files only after submitting information --name-status displays the list of new, modified, and deleted files --abbrev-commit displays only the first few characters of SHA-1, Instead of all 40 characters --relative-date displays shorter relative times (e.g., "2 weeks ago") --graph displays branch merge history represented by ASCII graphics -- Pretty displays historical submissions in other formats. Available options include oneline, short, Full, Fuller, and format (followed by the specified format) -- Pretty =tformat: You can customize the format of the record to be displayed, so that the output is easy to extract for later programming analysis (e.g. Git)log --pretty=format:""%h - %an, %ar : %s""%H Short hash of the commit object %T short hash of the tree object %P Full hash of the parent object %P short hash of the parent object %an Author name % AE author email address % AD author revision date (you can customize the format with the -date= option) %ar Author revision date, which displays %cn committer name % CE committer email address %cdCommit date %cr Commit date, how far back in time to display %s commit instructions --since limits the scope of the display output (e.g. Git)log--since=2.weeks Displays the last two weeks commit) option Description -(n) Displays only the last N commit. --since, --after Displays only the commit after the specified time. --until, --before displays only submissions before the specified time. --author displays only the submissions associated with the specified author. Committer displays only the commits associated with the specified committer.Copy the code
Some example

Git log –until=1.minute.ago All logs generated one minute ago

Git log –since=1.day.ago

Git log –since=1.hour.ago

Git log –since=1.month.ago –until=2.weeks. Ago

Git log –since ==2017-12-01 –until=2017-12-31

Git blame [file] look at the history of a file

Note: The command set above about Git must be run in the project directory managed by Git to be valid