{"thread":{"id":"16361","subject":"purging unwanted history","startedAt":"2008-11-17T00:26:23Z","lastAt":"2008-11-18T14:28:55Z","messageCount":5,"participants":["Geoff Russell","Björn Steinbrink","Marcel M. Cary"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"95998","messageId":"93c3eada0811161626h69929cd7va3fa4007a2341bae@mail.gmail.com","threadId":"16361","inReplyTo":null,"subject":"purging unwanted history","fromName":"Geoff Russell","fromEmail":"geoffrey.russell@gmail.com","sentAt":"2008-11-17T00:26:23Z","receivedAt":"2008-11-17T00:26:23Z","isPatch":false,"sender":{"key":"geoffrey.russell@gmail.com","avatar":"https://gravatar.com/avatar/c30f497ccfa6bf06d86f30bd2ba092a2dd124c61c6bc902f7cb5c3f6486947de?d=mp&s=160"},"body":"I have a repository with 5 years worth of history, I only want to keep\n1 year, so I want to purge the\nfirst 4 years. As it happens, the repository only has a single branch\nwhich should\nsimplify the problem.\n\nCheers,\n\nGeoff Russell\n\nP.S. Apologies, but I've asked this question before but didn't get an\nanswer which\nI understood or which worked, so perhaps my description of the problem\nwas faulty. This\nis a second attempt.\n"},{"id":"96004","messageId":"20081117022412.GB3911@atjola.homenet","threadId":"16361","inReplyTo":"93c3eada0811161626h69929cd7va3fa4007a2341bae@mail.gmail.com","subject":"Re: purging unwanted history","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2008-11-17T02:24:12Z","receivedAt":"2008-11-17T02:24:12Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2008.11.17 10:56:23 +1030, Geoff Russell wrote:\n> I have a repository with 5 years worth of history, I only want to keep\n> 1 year, so I want to purge the first 4 years. As it happens, the\n> repository only has a single branch which should simplify the problem.\n\nUse filter-branch to drop the parents on the first commit you want to\nkeep, and then drop the old cruft.\n\nLet's say $drop is the hash of the latest commit you want to drop. To\nkeep things sane and simple, make sure the first commit you want to\nkeep, ie. the child of $drop, is not a merge commit. Then you can use:\n\ngit filter-branch --parent-filter \"sed -e 's/-p $drop//'\" \\\n\t--tag-name-filter cat -- \\\n\t--all ^$drop\n\nThe above rewrites the parents of all commits that come \"after\" $drop.\n\nCheck the results with gitk.\n\n\nThen, to clean out all the old cruft.\n\nFirst, the backup references from filter-branch:\n\ngit for-each-ref --format='%(refname)' refs/original | \\\n\twhile read ref\n\tdo\n\t\tgit update-ref -d \"$ref\"\n\tdone\n\nThen clean your reflogs:\ngit reflog expire --expire=0 --all\n\nAnd finally, repack and drop all the old unreachable objects:\ngit repack -ad\ngit prune # For objects that repack -ad might have left around\n\nAt that point, everything leading up to and including $drop should be\ngone.\n\nHTH\nBjörn\n"},{"id":"96005","messageId":"20081117022714.GC3911@atjola.homenet","threadId":"16361","inReplyTo":"20081117022412.GB3911@atjola.homenet","subject":"Re: purging unwanted history","fromName":"Björn Steinbrink","fromEmail":"b.steinbrink@gmx.de","sentAt":"2008-11-17T02:27:14Z","receivedAt":"2008-11-17T02:27:14Z","isPatch":false,"sender":{"key":"b.steinbrink@gmx.de","avatar":"https://avatars.githubusercontent.com/u/230962?v=4"},"body":"On 2008.11.17 03:24:12 +0100, Björn Steinbrink wrote:\n> On 2008.11.17 10:56:23 +1030, Geoff Russell wrote:\n> > I have a repository with 5 years worth of history, I only want to keep\n> > 1 year, so I want to purge the first 4 years. As it happens, the\n> > repository only has a single branch which should simplify the problem.\n> \n> Use filter-branch to drop the parents on the first commit you want to\n> keep, and then drop the old cruft.\n> \n> Let's say $drop is the hash of the latest commit you want to drop. To\n> keep things sane and simple, make sure the first commit you want to\n> keep, ie. the child of $drop, is not a merge commit. Then you can use:\n> \n> git filter-branch --parent-filter \"sed -e 's/-p $drop//'\" \\\n> \t--tag-name-filter cat -- \\\n> \t--all ^$drop\n> \n> The above rewrites the parents of all commits that come \"after\" $drop.\n> \n> Check the results with gitk.\n> \n> \n> Then, to clean out all the old cruft.\n> \n> First, the backup references from filter-branch:\n> \n> git for-each-ref --format='%(refname)' refs/original | \\\n> \twhile read ref\n> \tdo\n> \t\tgit update-ref -d \"$ref\"\n> \tdone\n> \n> Then clean your reflogs:\n> git reflog expire --expire=0 --all\n> \n> And finally, repack and drop all the old unreachable objects:\n> git repack -ad\n> git prune # For objects that repack -ad might have left around\n> \n> At that point, everything leading up to and including $drop should be\n> gone.\n\nHm, on second thought, if you have tags referencing some of the old\nhistory, they'll still be around, I think. Just delete those before you\nstart the rewriting.\n\nAnd of course do the above with a copy of your repo. Just in case.\n\nBjörn\n"},{"id":"96006","messageId":"93c3eada0811161903v7b6c7abaq58cb6712190d03d5@mail.gmail.com","threadId":"16361","inReplyTo":"20081117022714.GC3911@atjola.homenet","subject":"Re: purging unwanted history","fromName":"Geoff Russell","fromEmail":"geoffrey.russell@gmail.com","sentAt":"2008-11-17T03:03:07Z","receivedAt":"2008-11-17T03:03:07Z","isPatch":false,"sender":{"key":"geoffrey.russell@gmail.com","avatar":"https://gravatar.com/avatar/c30f497ccfa6bf06d86f30bd2ba092a2dd124c61c6bc902f7cb5c3f6486947de?d=mp&s=160"},"body":"On Mon, Nov 17, 2008 at 12:57 PM, Björn Steinbrink <B.Steinbrink@gmx.de> wrote:\n> On 2008.11.17 03:24:12 +0100, Björn Steinbrink wrote:\n>> On 2008.11.17 10:56:23 +1030, Geoff Russell wrote:\n>> > I have a repository with 5 years worth of history, I only want to keep\n>> > 1 year, so I want to purge the first 4 years. As it happens, the\n>> > repository only has a single branch which should simplify the problem.\n>>\n>> Use filter-branch to drop the parents on the first commit you want to\n>> keep, and then drop the old cruft.\n>>\n>> Let's say $drop is the hash of the latest commit you want to drop. To\n>> keep things sane and simple, make sure the first commit you want to\n>> keep, ie. the child of $drop, is not a merge commit. Then you can use:\n>>\n>> git filter-branch --parent-filter \"sed -e 's/-p $drop//'\" \\\n>>       --tag-name-filter cat -- \\\n>>       --all ^$drop\n>>\n>> The above rewrites the parents of all commits that come \"after\" $drop.\n>>\n>> Check the results with gitk.\n>>\n>>\n>> Then, to clean out all the old cruft.\n>>\n>> First, the backup references from filter-branch:\n>>\n>> git for-each-ref --format='%(refname)' refs/original | \\\n>>       while read ref\n>>       do\n>>               git update-ref -d \"$ref\"\n>>       done\n>>\n>> Then clean your reflogs:\n>> git reflog expire --expire=0 --all\n>>\n>> And finally, repack and drop all the old unreachable objects:\n>> git repack -ad\n>> git prune # For objects that repack -ad might have left around\n>>\n>> At that point, everything leading up to and including $drop should be\n>> gone.\n>\n> Hm, on second thought, if you have tags referencing some of the old\n> history, they'll still be around, I think. Just delete those before you\n> start the rewriting.\n>\n> And of course do the above with a copy of your repo. Just in case.\n>\n> Björn\n>\n\nGreat, I've just tested this and it is exactly what I want. I'm still\ngetting my head around\nwhy, but understanding will arrive with a little more thought.\n\n\nMany thanks,\n\nGeoff\n\n\n\n-- \n6 Fifth Ave,\nSt Morris, S.A. 5068\nAustralia\nPh: 041 8805 184 / 08 8332 5069\n"},{"id":"96084","messageId":"4922D127.1020305@oak.homeunix.org","threadId":"16361","inReplyTo":"93c3eada0811161626h69929cd7va3fa4007a2341bae@mail.gmail.com","subject":"Re: purging unwanted history","fromName":"Marcel M. Cary","fromEmail":"marcel@oak.homeunix.org","sentAt":"2008-11-18T14:28:55Z","receivedAt":"2008-11-18T14:28:55Z","isPatch":false,"sender":{"key":"marcel@oak.homeunix.org","avatar":"https://gravatar.com/avatar/2bb524e4f383167b7e256bb93256c88353748d9873c34cde0fd461f1165baa0f?d=mp&s=160"},"body":"Geoff,\n\nI'm able to prune history with git filter-branch.  For example, to throw\naway history on the current branch before commit\n171d7661eda111d3e35f6e8097a1a3a07b30026c, I tried:\n\ngit filter-branch --parent-filter '\n    if [ $GIT_COMMIT = 171d7661eda111d3e35f6e8097a1a3a07b30026c ]; then\n        echo \"\";\n    else\n        read line;\n        echo $line;\n    fi'\n\nI found the diff between that commit and it's rewritten version was\nempty, and diffs to subsequent commits looked sane.  It took an hour on\nthe git repository with about 16k commits.  I probably should have\nexcluded all the commits I didn't want to keep to reduce processing time.\n\nHowever, after deleting all but the rewritten branch and cloning the\nrepository, I didn't notice any decrease in the size of .git/, so I'm\nnot sure why you'd want to do that.  Also, all the remaining commitIDs\nchanged so any previous clones would have a tough time merging with yours.\n\nAnother possibility whose results might be similar in runtime and\nrepository size would be to run git rebase --interactive and squash all\nthe commits together before the ones you want to keep.\n\nMarcel\n\n\nGeoff Russell wrote:\n> I have a repository with 5 years worth of history, I only want to keep\n> 1 year, so I want to purge the\n> first 4 years. As it happens, the repository only has a single branch\n> which should\n> simplify the problem.\n> \n> Cheers,\n> \n> Geoff Russell\n> \n> P.S. Apologies, but I've asked this question before but didn't get an\n> answer which\n> I understood or which worked, so perhaps my description of the problem\n> was faulty. This\n> is a second attempt.\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n> \n"}]}