{"id":7955,"date":"2021-11-15T23:46:35","date_gmt":"2021-11-15T22:46:35","guid":{"rendered":"https:\/\/michlstechblog.info\/blog\/?p=7955"},"modified":"2021-11-16T09:58:44","modified_gmt":"2021-11-16T08:58:44","slug":"git-search-in-all-version-of-a-file-for-a-specific-string","status":"publish","type":"post","link":"https:\/\/michlstechblog.info\/blog\/git-search-in-all-version-of-a-file-for-a-specific-string\/","title":{"rendered":"Git: Search in all versions of a file for a specific string"},"content":{"rendered":"<div class=\"twoclick_social_bookmarks_post_7955 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_7955')){$('.twoclick_social_bookmarks_post_7955').socialSharePrivacy({\"services\":{\"flattr\":{\"uid\":\"Michl\",\"status\":\"on\",\"the_title\":\"Git%3A%20Search%20in%20all%20versions%20of%20a%20file%20for%20a%20specific%20string\",\"the_excerpt\":\"Hi%2C%0D%0A%0D%0Ato%20search%20in%20all%20versions%20of%20a%20file%20for%20a%20specfic%20string%3A%0D%0AFirst%20get%20a%20list%20of%20all%20commits%2C%20then%20grep%20each%20commit%3A%0D%0A%20%28more%26hellip%3B%29\",\"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-search-in-all-version-of-a-file-for-a-specific-string\\\/\",\"post_id\":7955,\"post_title_referrer_track\":\"Git%3A+Search+in+all+versions+of+a+file+for+a+specific+string\",\"display_infobox\":\"on\"});}});\n\/* ]]> *\/<\/script><\/div><p>Hi,<\/p>\n<p>to search in all versions of a file for a specfic string:<br \/>\nFirst get a list of all commits, then grep each commit:<br \/>\n<!--more--><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nexport File=myFolder\/myFile\r\nfor Hash in `git rev-list HEAD -- $File`; do\r\n    git grep -i -F MySearch String $Hash:$File;\r\ndone\r\n<\/pre>\n<p>This will list all commits and the line where the string is found.<\/p>\n<p>If you want to search the whole repository for a string simple omit the $File variable<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nfor Hash in `git rev-list HEAD --`; do\r\n    echo COMMIT $Hash\r\n    git grep -i -F MySearchString $Hash;\r\ndone\r\n<\/pre>\n<p>Note: On older git versions and greater commits this sometimes raises a segmentation fault.<\/p>\n<p>If you just want to search within  a given time range use <\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nexport File=myFolder\/myFile\r\nfor Hash in `git rev-list --after=&quot;2021-08-31&quot; --until=&quot;2021-10-10&quot; HEAD -- $File`; do\r\n    git grep -i -F MySearch String $Hash:$File;\r\ndone\r\n<\/pre>\n<p>Michael<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, to search in all versions of a file for a specfic string: First get a list of all commits, then grep each commit:<\/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":[1662,249,250,1661,505,1660,794,1293,1663],"class_list":["post-7955","post","type-post","status-publish","format-standard","hentry","category-git","tag-date-range","tag-file","tag-find","tag-for","tag-git","tag-repoistory","tag-search","tag-string","tag-whole-repository"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/7955","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=7955"}],"version-history":[{"count":6,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/7955\/revisions"}],"predecessor-version":[{"id":7972,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/posts\/7955\/revisions\/7972"}],"wp:attachment":[{"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/media?parent=7955"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/categories?post=7955"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michlstechblog.info\/blog\/wp-json\/wp\/v2\/tags?post=7955"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}