{"id":9532,"date":"2013-02-27T10:56:28","date_gmt":"2013-02-27T05:26:28","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=9532"},"modified":"2013-02-27T10:56:28","modified_gmt":"2013-02-27T05:26:28","slug":"script-to-display-git-commits-for-creating-time-sheet","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/script-to-display-git-commits-for-creating-time-sheet\/","title":{"rendered":"Script to display Git commits for creating time sheet."},"content":{"rendered":"<p>We use &#8220;<em><strong>git log<\/strong><\/em>&#8221; many times a day while using Git in our projects. Sometimes we need to list <em>Git<\/em> commits between specific dates. Although,\u00a0Git provides command to do this but the syntax is too long to type.<\/p>\n<p>So I created a script named <strong><em><a title=\"timesheet\" href=\"https:\/\/github.com\/puneetbehl\/timesheet.git\" target=\"_blank\">timesheet<\/a><\/em><\/strong>, which facilitates us to display Git commits between two specific dates or after a specified date in prettified one line format for a specific author via very simple syntax. Below is the timesheet script:<\/p>\n<p>[sourcecode language=&#8221;bash&#8221;]<br \/>\n   #!\/bin\/bash<\/p>\n<p>   TODAY=`date +%Y%m%d`<br \/>\n   EXPECTED_ARGS=1<br \/>\n   E_BADARGS=65<br \/>\n   AUTHOR_NAME_REGEX=&quot;.*&quot;<br \/>\n   DATE_REGEX=&quot;[1-9][0-9][0-9][0-9]-[0-1][0-9]-[0-3][0-9]&quot;<br \/>\n   DAY_REGEX=&quot;[0-3][0-9]&quot;<br \/>\n   if [ $# -lt $EXPECTED_ARGS ]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short<br \/>\n   fi<\/p>\n<p>   if [[ $# -eq $EXPECTED_ARGS &amp;&amp; $1 =~ $AUTHOR_NAME_REGEX ]]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short &#8211;author=$1<br \/>\n   fi<\/p>\n<p>   if [[ $# -eq $EXPECTED_ARGS &amp;&amp; $1 =~ $DATE_REGEX ]]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short &#8211;after={$1}<br \/>\n   fi<\/p>\n<p>   if [[ $# -gt $EXPECTED_ARGS &amp;&amp; $# -eq 2 &amp;&amp; $1 =~ $DATE_REGEX &amp;&amp; $2 =~ $AUTHOR_NAME_REGEX ]]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short &#8211;after={$1} &#8211;author=$2<br \/>\n   fi<\/p>\n<p>   if [[ $# -gt $EXPECTED_ARGS &amp;&amp; $# -eq 2 &amp;&amp; $1 =~ $DATE_REGEX &amp;&amp; $2 =~ $DATE_REGEX ]]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short &#8211;after={$1} &#8211;before={$2}<br \/>\n   fi<\/p>\n<p>   if [[ $# -gt $EXPECTED_ARGS &amp;&amp; $# -eq 3 &amp;&amp; $1 =~ $DATE_REGEX &amp;&amp; $2 =~ $DATE_REGEX &amp;&amp; $3 =~ $AUTHOR_NAME_REGEX ]]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short &#8211;after={$1} &#8211;before=${2} &#8211;author=$3<br \/>\n   fi<\/p>\n<p>   if [[ $# -eq $EXPECTED_ARGS &amp;&amp; $1 =~ $DAY_REGEX ]]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short &#8211;after={$1-%m-%Y}<br \/>\n   fi<\/p>\n<p>   if [[ $# -gt $EXPECTED_ARGS &amp;&amp; $# -eq 2 &amp;&amp; $1 =~ $DAY_REGEX &amp;&amp; $2 =~ $DAY_REGEX ]]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short &#8211;after={$1-%m-%Y} &#8211;before={$2-%m-%Y}<br \/>\n   fi<\/p>\n<p>   if [[ $# -gt $EXPECTED_ARGS &amp;&amp; $# -eq 2 &amp;&amp; $1 =~ $DAY_REGEX &amp;&amp; $2 =~ $AUTHOR_NAME_REGEX ]]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short &#8211;after={$1-%m-%Y} &#8211;author=$2<br \/>\n   fi<\/p>\n<p>   if [[ $# -gt $EXPECTED_ARGS &amp;&amp; $# -eq 3 &amp;&amp; $1 =~ $DAY_REGEX &amp;&amp; $2 =~ $DAY_REGEX &amp;&amp; $3 =~ $AUTHOR_NAME_REGEX ]]<br \/>\n   then<br \/>\n       git log &#8211;pretty=&quot;short&quot; &#8211;format=%Cblue%h%&#8217; &#8216;Cgreen%an[%ad]%&#8217; &#8216;Creset%s%n &#8211;date=short &#8211;after={$1-%m-%Y} &#8211;before={$2-%m-%Y} &#8211;author=$3<br \/>\n   fi<br \/>\n[\/sourcecode]<\/p>\n<p><strong>Installation<\/strong><br \/>\nIn case of Ubuntu<\/p>\n<ol>\n<li>Open the terminal.<\/li>\n<li>Open the file .gitconfig in your home directory using your favorite text editor. (e.g: gedit, vim, vi)<\/li>\n<li>Check that the script file has executable permissions. (if not change via chmod command)<\/li>\n<li>Create an alias for the script in .gitconfig as shown below:<br \/>\n[sourcecode language=&#8221;bash&#8221;]<br \/>\n[alias]<br \/>\ntimesheet = ! &lt;PATH_TO_SCRIPT_FILE&gt;\/timesheet<br \/>\n [\/sourcecode]<\/li>\n<\/ol>\n<p><strong>Usage<\/strong><br \/>\nSome of the usages are given below:<\/p>\n<p>[bash]<br \/>\n   git timesheet<br \/>\n   git timesheet &lt;START_DAY_OF_CURRENT_MONTH&gt;<br \/>\n   git timesheet &lt;START_DAY&gt; &lt;END_DAY&gt;<br \/>\n   git timesheet &lt;START_DATE&gt;<br \/>\n   git timesheet &lt;START_DATE&gt; &lt;END_DATE&gt;<br \/>\n   git timesheet &lt;AUTHOR_NAME&gt;<br \/>\n   git timesheet &lt;START_DAY&gt; &lt;AUTHOR_NAME&gt;<br \/>\n   git timesheet &lt;START_DAY&gt; &lt;END_DAY&gt; &lt;AUTHOR_NAME&gt;<br \/>\n   git timesheet &lt;START_DATE&gt; &lt;AUTHOR_NAME&gt;<br \/>\n   git timesheet &lt;START_DATE&gt; &lt;END_DATE&gt; &lt;AUTHOR_NAME&gt;<br \/>\n[\/bash]<\/p>\n<p><strong>Example<\/strong><\/p>\n<p>[bash]<br \/>\ngit timesheet 15 17<br \/>\nor<br \/>\ngit timesheet 2013-02-15 2013-02-17<br \/>\nor<br \/>\ngit timesheet 15 17 &lt;AUTHOR_NAME&gt;<br \/>\n[\/bash]<\/p>\n<p><strong>Note:<\/strong> One can specify dates as 15 or 17 only for current month otherwise dates should be in yyyy-mm-dd (2013-02-15) format.<\/p>\n<p><em>Please share your feedback and suggestions.<\/em><\/p>\n<hr \/>\n<p style=\"text-align: right\"><strong><em><a title=\"timesheet\" href=\"https:\/\/github.com\/puneetbehl\/timesheet.git\" target=\"_blank\">Read more about timesheet script on GitHub \u00bb<\/a><\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We use &#8220;git log&#8221; many times a day while using Git in our projects. Sometimes we need to list Git commits between specific dates. Although,\u00a0Git provides command to do this but the syntax is too long to type. So I created a script named timesheet, which facilitates us to display Git commits between two specific [&hellip;]<\/p>\n","protected":false},"author":57,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":10},"categories":[7],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/9532"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/57"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=9532"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/9532\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=9532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=9532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=9532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}