{"thread":{"id":"16783","subject":"is it possible filter the revision history of a single file into another repository?","startedAt":"2008-12-18T13:51:12Z","lastAt":"2008-12-19T13:17:05Z","messageCount":8,"participants":["Whit Armstrong","Thomas Jarosch","Sverre Rabbelier"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"98252","messageId":"8ec76080812180551p8c97a0dqa2025e67792946c7@mail.gmail.com","threadId":"16783","inReplyTo":null,"subject":"is it possible filter the revision history of a single file into another repository?","fromName":"Whit Armstrong","fromEmail":"armstrong.whit@gmail.com","sentAt":"2008-12-18T13:51:12Z","receivedAt":"2008-12-18T13:51:12Z","isPatch":false,"sender":{"key":"armstrong.whit@gmail.com","avatar":"https://gravatar.com/avatar/3977f2e287db4d4de47839714313edee1222fa9d68677e1de922ec243da4b77d?d=mp&s=160"},"body":"For instance, if my repository contains foo.c, and 100 other files.\n\nI would like to create a new and separate repository containing only\nthe revision history of foo.c.\n\nWould someone mind pointing me at some documentation for this\nprocedure if it exists?\n\nThanks very much,\nWhit\n"},{"id":"98255","messageId":"200812181504.02105.thomas.jarosch@intra2net.com","threadId":"16783","inReplyTo":"8ec76080812180551p8c97a0dqa2025e67792946c7@mail.gmail.com","subject":"Re: is it possible filter the revision history of a single file into another repository?","fromName":"Thomas Jarosch","fromEmail":"thomas.jarosch@intra2net.com","sentAt":"2008-12-18T14:04:01Z","receivedAt":"2008-12-18T14:04:01Z","isPatch":false,"sender":{"key":"thomas.jarosch@intra2net.com","avatar":"https://avatars.githubusercontent.com/u/1146758?v=4"},"body":"On Thursday, 18. December 2008 14:51:12 Whit Armstrong wrote:\n> For instance, if my repository contains foo.c, and 100 other files.\n>\n> I would like to create a new and separate repository containing only\n> the revision history of foo.c.\n>\n> Would someone mind pointing me at some documentation for this\n> procedure if it exists?\n\nThis worked for me:\n\ngit filter-branch --tag-name-filter cat --index-filter \\\n    'git ls-files -s |grep -P \"\\t(DIR1|DIR2)\" \\\n    |GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&\n    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' -- --all\n\nRun \"git ls-files -s\" to see the output format.\nReplace the \"DIR1|DIR2\" with \"foo.c\".\n\nLater on you might want to remove empty commits from the history:\ngit filter-branch --tag-name-filter cat --commit-filter 'if [ z$1 = z`git rev-parse $3^{tree}` ]; then skip_commit \"$@\"; else git commit-tree \"$@\"; fi' \"$@\" -- --all\n\nIf you want to run two filter-branch commands in a row\nor you want to free up the space in .git afterwards:\n\n- git for-each-ref --format='%(refname)' refs/original | xargs -i git update-ref -d {}\n- git reflog expire --expire=0 --all\n- git repack -a -d\n- git prune\n\nCheers,\nThomas\n"},{"id":"98256","messageId":"bd6139dc0812180615v34d9aa7dj4b24ddf049b5615e@mail.gmail.com","threadId":"16783","inReplyTo":"8ec76080812180551p8c97a0dqa2025e67792946c7@mail.gmail.com","subject":"Re: is it possible filter the revision history of a single file into another repository?","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2008-12-18T14:15:04Z","receivedAt":"2008-12-18T14:15:04Z","isPatch":false,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"On Thu, Dec 18, 2008 at 14:51, Whit Armstrong <armstrong.whit@gmail.com> wrote:\n> For instance, if my repository contains foo.c, and 100 other files.\n>\n> I would like to create a new and separate repository containing only\n> the revision history of foo.c.\n>\n> Would someone mind pointing me at some documentation for this\n> procedure if it exists?\n\nI think \"git filter-branch\" is what you need. Have it filter out\nchanges to files but foo.c, and then remove all empty commits.\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"98257","messageId":"8ec76080812180619k78a28e30t591b514148202869@mail.gmail.com","threadId":"16783","inReplyTo":"200812181504.02105.thomas.jarosch@intra2net.com","subject":"Re: is it possible filter the revision history of a single file into another repository?","fromName":"Whit Armstrong","fromEmail":"armstrong.whit@gmail.com","sentAt":"2008-12-18T14:19:17Z","receivedAt":"2008-12-18T14:19:17Z","isPatch":false,"sender":{"key":"armstrong.whit@gmail.com","avatar":"https://gravatar.com/avatar/3977f2e287db4d4de47839714313edee1222fa9d68677e1de922ec243da4b77d?d=mp&s=160"},"body":"thanks, I will give this a try.\n\nOn Thu, Dec 18, 2008 at 9:04 AM, Thomas Jarosch\n<thomas.jarosch@intra2net.com> wrote:\n> On Thursday, 18. December 2008 14:51:12 Whit Armstrong wrote:\n>> For instance, if my repository contains foo.c, and 100 other files.\n>>\n>> I would like to create a new and separate repository containing only\n>> the revision history of foo.c.\n>>\n>> Would someone mind pointing me at some documentation for this\n>> procedure if it exists?\n>\n> This worked for me:\n>\n> git filter-branch --tag-name-filter cat --index-filter \\\n>    'git ls-files -s |grep -P \"\\t(DIR1|DIR2)\" \\\n>    |GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&\n>    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' -- --all\n>\n> Run \"git ls-files -s\" to see the output format.\n> Replace the \"DIR1|DIR2\" with \"foo.c\".\n>\n> Later on you might want to remove empty commits from the history:\n> git filter-branch --tag-name-filter cat --commit-filter 'if [ z$1 = z`git rev-parse $3^{tree}` ]; then skip_commit \"$@\"; else git commit-tree \"$@\"; fi' \"$@\" -- --all\n>\n> If you want to run two filter-branch commands in a row\n> or you want to free up the space in .git afterwards:\n>\n> - git for-each-ref --format='%(refname)' refs/original | xargs -i git update-ref -d {}\n> - git reflog expire --expire=0 --all\n> - git repack -a -d\n> - git prune\n>\n> Cheers,\n> Thomas\n>\n>\n"},{"id":"98278","messageId":"8ec76080812181151y4a5a6f5cna57785c935032e77@mail.gmail.com","threadId":"16783","inReplyTo":"8ec76080812180619k78a28e30t591b514148202869@mail.gmail.com","subject":"Re: is it possible filter the revision history of a single file into another repository?","fromName":"Whit Armstrong","fromEmail":"armstrong.whit@gmail.com","sentAt":"2008-12-18T19:51:38Z","receivedAt":"2008-12-18T19:51:38Z","isPatch":false,"sender":{"key":"armstrong.whit@gmail.com","avatar":"https://gravatar.com/avatar/3977f2e287db4d4de47839714313edee1222fa9d68677e1de922ec243da4b77d?d=mp&s=160"},"body":"Sorry, seem to be getting this error:\n`/home/whit/dvl/risk.metrics.utils/RiskMetrics/.git-rewrite/t/../index.new':\nNo such file or directory\n\ndo I need to set up the index file first?\n\nIs there a good site that documents this procedure?\n\n[whit@linuxsvr RiskMetrics]$ git filter-branch --tag-name-filter cat\n--index-filter \\\n>    'git ls-files -s |grep -P \"riskmetrics.rb\" \\\n>    |GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&\n>    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' -- --all\nRewrite 8f1a0eaae033d109f4a3a4b410bd8e04dd9997db (1/481)mv: cannot\nstat `/home/whit/dvl/risk.metrics.utils/RiskMetrics/.git-rewrite/t/../index.new':\nNo such file or directory\nindex filter failed: git ls-files -s |grep -P \"riskmetrics.rb\" \\\n   |GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&\n   mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE\n[whit@linuxsvr RiskMetrics]$\n\n\n\nOn Thu, Dec 18, 2008 at 9:19 AM, Whit Armstrong\n<armstrong.whit@gmail.com> wrote:\n> thanks, I will give this a try.\n>\n> On Thu, Dec 18, 2008 at 9:04 AM, Thomas Jarosch\n> <thomas.jarosch@intra2net.com> wrote:\n>> On Thursday, 18. December 2008 14:51:12 Whit Armstrong wrote:\n>>> For instance, if my repository contains foo.c, and 100 other files.\n>>>\n>>> I would like to create a new and separate repository containing only\n>>> the revision history of foo.c.\n>>>\n>>> Would someone mind pointing me at some documentation for this\n>>> procedure if it exists?\n>>\n>> This worked for me:\n>>\n>> git filter-branch --tag-name-filter cat --index-filter \\\n>>    'git ls-files -s |grep -P \"\\t(DIR1|DIR2)\" \\\n>>    |GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&\n>>    mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE' -- --all\n>>\n>> Run \"git ls-files -s\" to see the output format.\n>> Replace the \"DIR1|DIR2\" with \"foo.c\".\n>>\n>> Later on you might want to remove empty commits from the history:\n>> git filter-branch --tag-name-filter cat --commit-filter 'if [ z$1 = z`git rev-parse $3^{tree}` ]; then skip_commit \"$@\"; else git commit-tree \"$@\"; fi' \"$@\" -- --all\n>>\n>> If you want to run two filter-branch commands in a row\n>> or you want to free up the space in .git afterwards:\n>>\n>> - git for-each-ref --format='%(refname)' refs/original | xargs -i git update-ref -d {}\n>> - git reflog expire --expire=0 --all\n>> - git repack -a -d\n>> - git prune\n>>\n>> Cheers,\n>> Thomas\n>>\n>>\n>\n"},{"id":"98348","messageId":"200812191044.47830.thomas.jarosch@intra2net.com","threadId":"16783","inReplyTo":"8ec76080812181151y4a5a6f5cna57785c935032e77@mail.gmail.com","subject":"Re: is it possible filter the revision history of a single file into another repository?","fromName":"Thomas Jarosch","fromEmail":"thomas.jarosch@intra2net.com","sentAt":"2008-12-19T09:44:37Z","receivedAt":"2008-12-19T09:44:37Z","isPatch":false,"sender":{"key":"thomas.jarosch@intra2net.com","avatar":"https://avatars.githubusercontent.com/u/1146758?v=4"},"body":"On Thursday, 18. December 2008 20:51:38 Whit Armstrong wrote:\n> Sorry, seem to be getting this error:\n> `/home/whit/dvl/risk.metrics.utils/RiskMetrics/.git-rewrite/t/../index.new'\n>: No such file or directory\n>\n> do I need to set up the index file first?\n\nHmm, I guess you have an empty commit in your repository like I did.\nThis is currently a corner case in update-index, which does not create empty \nindex files. I posted a patch a few days ago and Junio posted an updated \nversion of that. I could send you my version for git 1.6.0.5 if you need it.\n\n> Is there a good site that documents this procedure?\n\nA good start is the git-filter-branch man page and the mailinglist archive.\n\nThomas\n"},{"id":"98353","messageId":"8ec76080812190508v2ef0f982pab66a698f06a80d5@mail.gmail.com","threadId":"16783","inReplyTo":"200812191044.47830.thomas.jarosch@intra2net.com","subject":"Re: is it possible filter the revision history of a single file into another repository?","fromName":"Whit Armstrong","fromEmail":"armstrong.whit@gmail.com","sentAt":"2008-12-19T13:08:23Z","receivedAt":"2008-12-19T13:08:23Z","isPatch":false,"sender":{"key":"armstrong.whit@gmail.com","avatar":"https://gravatar.com/avatar/3977f2e287db4d4de47839714313edee1222fa9d68677e1de922ec243da4b77d?d=mp&s=160"},"body":"thanks, Thomas. I could definitely pull from your tree.  seems like\nthe path of least resistance to get my repo split.\n\nCheers,\nWhit\n\n\nOn Fri, Dec 19, 2008 at 4:44 AM, Thomas Jarosch\n<thomas.jarosch@intra2net.com> wrote:\n> On Thursday, 18. December 2008 20:51:38 Whit Armstrong wrote:\n>> Sorry, seem to be getting this error:\n>> `/home/whit/dvl/risk.metrics.utils/RiskMetrics/.git-rewrite/t/../index.new'\n>>: No such file or directory\n>>\n>> do I need to set up the index file first?\n>\n> Hmm, I guess you have an empty commit in your repository like I did.\n> This is currently a corner case in update-index, which does not create empty\n> index files. I posted a patch a few days ago and Junio posted an updated\n> version of that. I could send you my version for git 1.6.0.5 if you need it.\n>\n>> Is there a good site that documents this procedure?\n>\n> A good start is the git-filter-branch man page and the mailinglist archive.\n>\n> Thomas\n>\n>\n"},{"id":"98354","messageId":"200812191417.13147.thomas.jarosch@intra2net.com","threadId":"16783","inReplyTo":"8ec76080812190508v2ef0f982pab66a698f06a80d5@mail.gmail.com","subject":"Re: is it possible filter the revision history of a single file into another repository?","fromName":"Thomas Jarosch","fromEmail":"thomas.jarosch@intra2net.com","sentAt":"2008-12-19T13:17:05Z","receivedAt":"2008-12-19T13:17:05Z","isPatch":false,"sender":{"key":"thomas.jarosch@intra2net.com","avatar":"https://avatars.githubusercontent.com/u/1146758?v=4"},"body":"On Friday, 19. December 2008 14:08:23 Whit Armstrong wrote:\n> thanks, Thomas. I could definitely pull from your tree.  seems like\n> the path of least resistance to get my repo split.\n\nHere's the patch I use for git 1.6.0.5. According to Junio\nit has the small drawback of always writing out the index,\neven if there are no changes.\n\nIf you need an updated patch against HEAD, look for Junio's reply\nto my patch in the list archive.\n\nEnjoy,\nThomas\n\nSigned-off-by: Thomas Jarosch <thomas.jarosch@intra2net.com>\n\n--- git-1.6.0.5/builtin-update-index.c\t2008-12-08 02:21:49.000000000 +0100\n+++ git-1.6.0.5.index/builtin-update-index.c\t2008-12-13 12:43:14.000000000 \n+0100\n@@ -297,6 +297,8 @@ static void read_index_info(int line_ter\n \tstruct strbuf buf;\n \tstruct strbuf uq;\n \n+\tint found_something = 0;\n+\n \tstrbuf_init(&buf, 0);\n \tstrbuf_init(&uq, 0);\n \twhile (strbuf_getline(&buf, stdin, line_termination) != EOF) {\n@@ -307,6 +309,8 @@ static void read_index_info(int line_ter\n \t\tunsigned long ul;\n \t\tint stage;\n \n+\t\tfound_something = 1;\n+\n \t\t/* This reads lines formatted in one of three formats:\n \t\t *\n \t\t * (1) mode         SP sha1          TAB path\n@@ -382,6 +386,11 @@ static void read_index_info(int line_ter\n \tbad_line:\n \t\tdie(\"malformed index info %s\", buf.buf);\n \t}\n+\n+\t/* Force creation of empty index - needed by git filter-branch */\n+\tif (!found_something)\n+\t\tactive_cache_changed = 1;\n+\n \tstrbuf_release(&buf);\n \tstrbuf_release(&uq);\n }\n"}]}