{"id":3462,"date":"2016-08-10T16:29:38","date_gmt":"2016-08-10T16:29:38","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=3462"},"modified":"2016-08-13T14:11:37","modified_gmt":"2016-08-13T14:11:37","slug":"a-git-pre-commit-hook-to-do-svn-style-date-substitution","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2016\/08\/a-git-pre-commit-hook-to-do-svn-style-date-substitution\/","title":{"rendered":"A git pre-commit hook to do SVN style $Date$ substitution"},"content":{"rendered":"<p>Put the following in .git\/pre-commit (make sure it&#8217;s executable):<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit diff --cached --name-only &gt; commits_list\r\n<\/pre>\n<p>And the following in .git\/post-commit:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n#!\/bin\/bash\r\n\r\nif &#x5B; -f commits_list ]\r\nthen\r\n\tcurrentdate=`date`\r\n\r\n\tcat commits_list | while read F\r\n\tdo\r\n \t echo $PWD\/$F\r\n \t filebase=`basename $F`\r\n \t sed -i -e 's\/\\$Date&#x5B;^$]*\\$\/\\$Date '&quot;$currentdate&quot;'\\$\/' $PWD\/$F\r\n \t sed -i -e 's\/\\$Filename&#x5B;^$]*\\$\/\\$Filename '&quot;$filebase&quot;'\\$\/' $PWD\/$F\r\n\t git add $PWD\/$F\r\n\tdone \r\n\r\n\trm commits_list\r\n\tgit commit --amend --no-verify -C HEAD\r\n\r\nfi\r\n\r\n<\/pre>\n<p>Still not extensively tested&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Put the following in .git\/pre-commit (make sure it&#8217;s executable): git diff &#8211;cached &#8211;name-only &gt; commits_list And the following in .git\/post-commit: #!\/bin\/bash if &#x5B; -f commits_list ] then currentdate=`date` cat commits_list | while read F do echo $PWD\/$F filebase=`basename $F` sed -i -e &#8216;s\/\\$Date&#x5B;^$]*\\$\/\\$Date &#8216;&quot;$currentdate&quot;&#8217;\\$\/&#8217; $PWD\/$F sed -i -e &#8216;s\/\\$Filename&#x5B;^$]*\\$\/\\$Filename &#8216;&quot;$filebase&quot;&#8217;\\$\/&#8217; $PWD\/$F git add $PWD\/$F done [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-3462","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-TQ","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/3462","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=3462"}],"version-history":[{"count":4,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/3462\/revisions"}],"predecessor-version":[{"id":3466,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/3462\/revisions\/3466"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=3462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=3462"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=3462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}