{"id":7950,"date":"2021-11-15T21:59:05","date_gmt":"2021-11-15T20:59:05","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=7950"},"modified":"2021-11-16T09:29:59","modified_gmt":"2021-11-16T08:29:59","slug":"git-export-all-versions-of-a-file-within-a-given-time-range","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/git-export-all-versions-of-a-file-within-a-given-time-range\/","title":{"rendered":"Git: Export all versions of a file within a given time range"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_7950 social_share_privacy clearfix 1.6.4 locale-en_US sprite-en_US\"><\/div><div class=\"twoclick-js\"><script type=\"text\/javascript\">\/* <![CDATA[ *\/\njQuery(document).ready(function($){if($('.twoclick_social_bookmarks_post_7950')){$('.twoclick_social_bookmarks_post_7950').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Git%3A%20Export%20all%20versions%20of%20a%20file%20within%20a%20given%20time%20range\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Ain%20some%20cases%20I%20uses%20git%20repositories%20for%20versioning%20log%20files%20and%20want%20to%20export%20a%20specific%20logfile%20in%20all%20versions%3A%0D%0A%0D%0A%5Bshell%5D%0D%0Afor%20CommitHash%20in%20%60git%20rev-list%20HEAD%20--%20myFolder%2Fmyfile%60%3B%20do%0D%0A%20%20%20%20git%20show%20%24%7BCommitHash%7D%3AmyFolder%2Fmyfile%20%26gt%3B%20export%2F%24%7BCommitHash%7D_myfile%0D%0Adone%0D%0A%5B%2Fshell%5D%0D%0Acombined%20with%20given%20time%20range%0D%0A%5Bshell%5D%0D%0Agit%20%20rev-list%20--after%3D%26quot%3B2021-08-31%26quot%3B%20--until%3D%26quot%3B2021%20...\",\"txt_info\":\"2 clicks for more data protection:\\r\\n\\r\\nOnly when you click here, the button will be come active and you can send your recommendation to Flattr. When activating, data are transmitted to third parties. \",\"perma_option\":\"off\"}},\"txt_help\":\"When you activate these fields by clicking, information to Flattr may be transferred abroad, and probably may also stored there.\",\"settings_perma\":\"Enable permanently and accept data transmission. \",\"info_link\":\"http:\\\/\\\/www.heise.de\\\/ct\\\/artikel\\\/2-Klicks-fuer-mehr-Datenschutz-1333879.html\",\"uri\":\"https:\\\/\\\/michlstechblog.info\\\/blog\\\/git-export-all-versions-of-a-file-within-a-given-time-range\\\/\",\"post_id\":7950,\"post_title_referrer_track\":\"Git%3A+Export+all+versions+of+a+file+within+a+given+time+range\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>in some cases I uses git repositories for versioning log files and want to export a specific logfile in all versions:<br \/>\n<!-- \n\n<pre class=\"lang-sh s-code-block\"><code class=\"hljs language-bash\"><span class=\"hljs-keyword\">for<\/span> CommitHash `git rev-list HEAD -- myFolder\/myfile`; <span class=\"hljs-keyword\">do<\/span>\r\n    git show <span class=\"hljs-variable\">${CommitHash}<\/span>:myFolder\/myfile &gt; export\/<span class=\"hljs-variable\">${sha}<\/span>_myfile\r\n<span class=\"hljs-keyword\">done<\/span>\r\n<\/code><\/pre>\n\n --><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nfor CommitHash in `git rev-list HEAD -- myFolder\/myfile`; do\r\n    git show ${CommitHash}:myFolder\/myfile &gt; export\/${CommitHash}_myfile\r\ndone\r\n<\/pre>\n<p>combined with given time range<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit  rev-list --after=&quot;2021-08-31&quot; --until=&quot;2021-10-10&quot; HEAD\r\n<\/pre>\n<p>and the the date of a commit in the filename<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ngit show --format=%cd -s --date=format:'%Y%m%d-%H%M%S' 8dba4dd6ef44fe0c069ec87eb179ac8f8ae2222c\r\n<\/pre>\n<p>This should be this one:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nexport File=myFolder\/myfile\r\nexport ExportFolder=\/tmp\r\nfor CommitHash in `git rev-list --after=&quot;2021-11-01&quot; --until=&quot;2021-11-16&quot; HEAD -- $File`; do\r\n    export CommitDate=$(git show --format=%cd -s --date=format:'%Y%m%d-%H%M%S' ${CommitHash})\r\n    export ExportFileName=${ExportFolder}\/${File}_${CommitDate}_${CommitHash} \r\n    echo Exporting $ExportFileName  \r\n    git show ${CommitHash}:${File} &gt; $ExportFileName\r\ndone\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, in some cases I uses git repositories for versioning log files and want to export a specific logfile in all versions: for CommitHash in `git rev-list HEAD &#8212; myFolder\/myfile`; do git show ${CommitHash}:myFolder\/myfile &gt; export\/${CommitHash}_myfile done combined with given time range git rev-list &#8211;after=&quot;2021-08-31&quot; &#8211;until=&quot;2021-10-10&quot; HEAD and the the date of a commit in &hellip; <a href=\"https:\/\/michlstechblog.info\/blog\/git-export-all-versions-of-a-file-within-a-given-time-range\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Git: Export all versions of a file within a given time range<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[805],"tags":[1664,1662,394,249,505,1665],"class_list":["post-7950","post","type-post","status-publish","format-standard","hentry","category-git","tag-all","tag-date-range","tag-export","tag-file","tag-git","tag-versions"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/7950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/comments?post=7950"}],"version-history":[{"count":14,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/7950\/revisions"}],"predecessor-version":[{"id":7971,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/7950\/revisions\/7971"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=7950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=7950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=7950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}