bcthew
Last Updated: September 09, 2019
·
23.56K
· mavimo

Create your work report using Git Log

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"

(ATTENTION: escape " in format using \ )

Now you can generate CSV report using:

git report-csv > report.csv

Yeap, report activities is now REALLY more easy ;)

(of course you MUST use verbose and self explicative commit message, but this is your standard, right ;) )

Authored by Marco Vito Moscaritolo

16 Responses
Add your response

8874

I've never been asked for an activity report, but this is awesome. I'm putting this in my global config just for me!

over 1 year ago ·
8876

@katylava Yeap! this is usefull also to have opportunity to evaluate our estimation like: how many work I do on theming? This quantity of activity match with my "estimation"? (NB: no time related but "work" related)

over 1 year ago ·
8963

Great tip
How can I change format to display author also?

over 1 year ago ·
8974

Add %an in the alias, for example:

report = "log --author=YOURNAME --since='2 sunday ago' --until='1 sunday ago' --format='%Cgreen%ci%Creset (%an) %s%Creset' --no-merges"

over 1 year ago ·
9043

Often I'll use git log at/for/during the daily scrum. In that scenario the command can be a little easier since you don't need the timestamps, and thus may not need an alias, which is nice since that'll help you remember some of git's various options:

git log --author=YOURNAME --since="Yesterday" --oneline --no-merges

And of course for Monday's scrum:

git log --author=YOURNAME --since="Last Friday" --oneline --no-merges

over 1 year ago ·
9047

Technically, I like this protip very much. However, in real business, I'm pretty sure that this is not the customers want 80% of the time. Anyway, manually writing a report is a useful way to force oneself to zoom out and re-think about the project.

over 1 year ago ·
9056

Thank you. That's very useful.

over 1 year ago ·
9079

@hupili Yes, but this is still useful as an intermediate summary, to remind you of things that should go into the big-picture view!

over 1 year ago ·
9080

@hupili you're right, this is just a "starting point", but speed drastically the report writing and improve accuracy (you can remember ALL activities that you do in a week?). As a side effect developer are encouraged to write verbose and easily understandable commit messages.

PS: I'm developer ;)

over 1 year ago ·
9081

@codehill: yeap! :)

over 1 year ago ·
9085

@mabraham @mavimo , yeah, I think using it as an intermediate step is reasonable. Treat it as a report that Git writes for you (to remind you of things happened last week) but not the report you write for the customer.

My observation is that the granularities of commits are very different. Some commits add new functions or important upgrades. Those will be meaningful if the messages are verbosely written. There are usually some small fixes, which are too detailed to present to the customer ( The post removes merge commits. I think it is for the same reason, :) ). Cumulating commits into natural function points is better for the communication.

I'm also developer. :)

over 1 year ago ·
9143

is it possible to receive the author as a parameter using the alias?

over 1 year ago ·
9147

@italolelis you can omit author param and set param each time do you need, eg.:

git report --author=FirstName
git report --author=SecondName
over 1 year ago ·
9150

@italolelis you can create an alias without author parameter and specify it on cli each time, eg.:

git report --author=Marco
git report --author=Vito
over 1 year ago ·
15227

I use the similar kind of procedure but I ran into some issues where some commits are missing in the date range that I am looking for.

It looks like those missing commits are having old dates (they were committed on a local dev branch few days before I merge it to my tracking branch). The merge commit showed up in the git log --since="1.day" but not the commit that it merged.

I can do a rebase here to get rid of this situation in future but Is there a way that I can deal with older such commits. ??

Basically, I want to get the full list of commits that are pushed to remote branch no matter what the AuthorDate/CommiterDate on the commit.

over 1 year ago ·
28562

I need files pushed also in same log which is generating using command: git log --after='2017-01-10' --before='2017-01-15' --pretty=format:'%h,%an,%ad,%s' | grep 'Jan 13'
Can anyone help me please

over 1 year ago ·