Create your work report using Git Log

Posted on

Sometime our customer require to have a report of activity we do in last week. This can be a boring activity for a developer, so I like generate this using information obtained from git log.

The first approach is to create a git log report only for my activity (we have some people that work on the same project), and can be done using author setting:

git log --author=Marco # Change with your name

This generate an output like:

commit ad5140bca518c676cd4a6e9b268f66d3ff89f992
Author: Marco Vito Moscaritolo <marco@agavee.com>
Date:   Fri Aug 23 12:50:41 2013 +0200

    refs #101: Lorem Ipsum commit message

commit 5d3d687cbdea09e334267312451065a4416ea5b1
Merge: 76c97d3 b7850f9
Author: Marco Vito Moscaritolo <marco@agavee.com>
Date:   Fri Aug 23 12:39:35 2013 +0200

    Merge branch 'master' of git.agavee.com:your-project/your-branch

commit 7e6e36eb78f3b07bcb12c0fa3c1e240e6634eccf
Author: Marco Vito Moscaritolo <marco@agavee.com>
Date:   Fri Aug 23 10:35:41 2013 +0200

    Lorem Ipsum commit message

commit f86221395bee652e08ab8d25c18445c27bb5b723
Author: Marco Vito Moscaritolo <marco@agavee.com>
Date:   Fri Aug 23 10:35:23 2013 +0200

    refs #101: Lorem Ipsum commit message

commit 31dc49c6a8da7eda699aff7814baa0af555618d8
Author: Marco Vito Moscaritolo <marco@agavee.com>
Date:   Thu Aug 22 09:26:40 2013 +0200

    refs #100: Lorem Ipsum commit message

Next step is to limit log to be show to last week (or last month or….). We can use since and until options:

git log --author=Marco --since='1 sunday ago' --until='now'

The output is similar but only limited to work from last sunday. We can also change timeframe to limit to last week:

git log --author=Marco --since='2 sunday ago' --until='1 sunday ago'

or you can create report in timeframe that you prefer.

This is not really readable, so I prefer to craete a compact view of report, using formatoption. This is use a string to define format to display information in log. The format that i prefer is:

%Cred%h%Creset %s %Cgreen(%ci) %Cblue<%an>%Creset

that display commit hash (%h) in red color(%Cred), commit message (%s) in standard color (%Creset), commit time (%ci) in green color (%Cgreen) and autor name (%an) in blue (%Cblue) and reset color. More elements you can use in format can be visible in official doc.

that generate:

ad5140b refs #101: Lorem Ipsum commit message (2013-08-23 12:50:41 2013 +0200) <Marco Vito Moscaritolo>
5d3d687 Merge branch 'master' of git.agavee.com:your-project/your-branch (2013-08-23 12:39:35 2013 +0200) <Marco Vito Moscaritolo>
7e6e36e Lorem Ipsum commit message (2013-08-23 10:35:41 2013 +0200) <Marco Vito Moscaritolo>
f862213 refs #101: Lorem Ipsum commit message (2013-08-23 10:35:23 2013 +0200) <Marco Vito Moscaritolo>
31dc49c refs #100: Lorem Ipsum commit message (2013-08-22 09:26:40 2013 +0200) <Marco Vito Moscaritolo>

Another really useful format display only date and commit message:

%Cgreen%ci%Creset %s%Creset

that generate:

git log --author=Marco --since='2 sunday ago' --until='1 sunday ago' --format='%Cgreen%ci%Creset %s%Creset'

2013-08-23 12:50:41 2013 +0200 refs #101: Lorem Ipsum commit message 
2003-08-23 12:39:35 2013 +0200 Merge branch 'master' of git.agavee.com:your-project/your-branch
2013-08-23 10:35:41 2013 +0200 Lorem Ipsum commit message 
2013-08-23 10:35:23 2013 +0200 refs #101: Lorem Ipsum commit message 
2013-08-22 09:26:40 2013 +0200 refs #100: Lorem Ipsum commit message

Now we have a basic report. Customer to not know what’s is a merge, so i prefer remove this messages using no-merges flag,

git log --author=Marco --since='2 sunday ago' --until='1 sunday ago' --format='%Cgreen%ci%Creset %s%Creset' --no-merges

2013-08-23 12:50:41 2013 +0200 refs #101: Lorem Ipsum commit message 
2013-08-23 10:35:41 2013 +0200 Lorem Ipsum commit message 
2013-08-23 10:35:23 2013 +0200 refs #101: Lorem Ipsum commit message 
2013-08-22 09:26:40 2013 +0200 refs #100: Lorem Ipsum commit message

Now we have a complete report of our activities.

Last really useful tip it the possibility to save this settings ad a git command, so we do not need to re-type all this options each time. To do this edit .git/config file in your repo and add:

[alias]
  report = "log --author=Marco --since='2 sunday ago' --until='1 sunday ago' --format='%Cgreen%ci%Creset %s%Creset' --no-merges"

Now you can obtains report just typing:

git report

you can create more reports, like:

report-csv = "log --author=Marco --since='2 sunday ago' --until='1 sunday ago' --format='"%ci"",""%s""' --no-merges""

Leave a Reply

Your email address will not be published.