{"thread":{"id":"15937","subject":"Removing some files from history","startedAt":"2008-10-17T10:38:54Z","lastAt":"2008-10-17T12:20:21Z","messageCount":5,"participants":["Gennady Kushnir","Jeff King","Michael J Gruber","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"93288","messageId":"96ed5eac0810170338s292fe858s1c092428a44a7ad2@mail.gmail.com","threadId":"15937","inReplyTo":null,"subject":"Removing some files from history","fromName":"Gennady Kushnir","fromEmail":"genkush@rujel.net","sentAt":"2008-10-17T10:38:54Z","receivedAt":"2008-10-17T10:38:54Z","isPatch":false,"sender":{"key":"genkush@rujel.net","avatar":null},"body":"Hello all\nI'm not yet subscribed, but I wish I shall get reply anyway\n\nI'm going to make my repository public, but I have found that one of\nmy files contains some private data that I would not like to share.\nIs it possible to remove that file from all commits in my local\nrepository history before publishing it?\nOr it would be easier to start publishing with just my current state\n(whith all private data cleaned up)?\n\nThanks in advance.\nGennady\n"},{"id":"93289","messageId":"20081017104243.GA15848@sigill.intra.peff.net","threadId":"15937","inReplyTo":"96ed5eac0810170338s292fe858s1c092428a44a7ad2@mail.gmail.com","subject":"Re: Removing some files from history","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-10-17T10:42:43Z","receivedAt":"2008-10-17T10:42:43Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 17, 2008 at 02:38:54PM +0400, Gennady Kushnir wrote:\n\n> I'm going to make my repository public, but I have found that one of\n> my files contains some private data that I would not like to share.\n> Is it possible to remove that file from all commits in my local\n> repository history before publishing it?\n\nYes, see \"git help filter-branch\". The first example given does exactly\nwhat you are asking for.\n\n-Peff\n"},{"id":"93290","messageId":"48F86E6A.7080102@fastmail.fm","threadId":"15937","inReplyTo":"96ed5eac0810170338s292fe858s1c092428a44a7ad2@mail.gmail.com","subject":"Re: Removing some files from history","fromName":"Michael J Gruber","fromEmail":"michaeljgruber+gmane@fastmail.fm","sentAt":"2008-10-17T10:52:26Z","receivedAt":"2008-10-17T10:52:26Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Gennady Kushnir venit, vidit, dixit 17.10.2008 12:38:\n> Hello all\n> I'm not yet subscribed, but I wish I shall get reply anyway\n> \n> I'm going to make my repository public, but I have found that one of\n> my files contains some private data that I would not like to share.\n> Is it possible to remove that file from all commits in my local\n> repository history before publishing it?\n> Or it would be easier to start publishing with just my current state\n> (whith all private data cleaned up)?\n> \n> Thanks in advance.\n> Gennady\nUse\n\ngit filter-branch --index-filter 'git rm --cached secret' -- --all\n\nor\n\ngit filter-branch --tree-filter 'rm -f secret' -- --all\n\nwhere 'secret' is the name of the file to be removed.\n\nAfter that, make sure you clean up your repo before publishing:\nClean out the original references (command on 1 line):\n\ngit for-each-ref  --format='%(refname)' refs/original |while read ref;\ndo git update-ref -d $ref;done\n\nClean out the reflog:\n\ngit reflog --expire=0 expire\n\nRemove the old objects and packs:\n\ngit prune\ngit repack -adf\n\n[Makes me feel this should be easier.]\n\nMichael\n"},{"id":"93292","messageId":"96ed5eac0810170451y69fd864jb44ef62bca468498@mail.gmail.com","threadId":"15937","inReplyTo":"48F86E6A.7080102@fastmail.fm","subject":"Re: Removing some files from history","fromName":"Gennady Kushnir","fromEmail":"genkush@rujel.net","sentAt":"2008-10-17T11:51:15Z","receivedAt":"2008-10-17T11:51:15Z","isPatch":false,"sender":{"key":"genkush@rujel.net","avatar":null},"body":"thank you for precise instructions.\n\nhowever I did not completely understand the part about references and reflog\nwhat are these? git tags?\n\nand another question:\ndid I understand it right, that I can even make some changes to that\nfile in history - not just simply delete one?\n\nGennady\n\n2008/10/17 Michael J Gruber <michaeljgruber+gmane@fastmail.fm>:\n> Gennady Kushnir venit, vidit, dixit 17.10.2008 12:38:\n>> Hello all\n>> I'm not yet subscribed, but I wish I shall get reply anyway\n>>\n>> I'm going to make my repository public, but I have found that one of\n>> my files contains some private data that I would not like to share.\n>> Is it possible to remove that file from all commits in my local\n>> repository history before publishing it?\n>> Or it would be easier to start publishing with just my current state\n>> (whith all private data cleaned up)?\n>>\n>> Thanks in advance.\n>> Gennady\n> Use\n>\n> git filter-branch --index-filter 'git rm --cached secret' -- --all\n>\n> or\n>\n> git filter-branch --tree-filter 'rm -f secret' -- --all\n>\n> where 'secret' is the name of the file to be removed.\n>\n> After that, make sure you clean up your repo before publishing:\n> Clean out the original references (command on 1 line):\n>\n> git for-each-ref  --format='%(refname)' refs/original |while read ref;\n> do git update-ref -d $ref;done\n>\n> Clean out the reflog:\n>\n> git reflog --expire=0 expire\n>\n> Remove the old objects and packs:\n>\n> git prune\n> git repack -adf\n>\n> [Makes me feel this should be easier.]\n>\n> Michael\n>\n"},{"id":"93293","messageId":"m34p3bjtx4.fsf@localhost.localdomain","threadId":"15937","inReplyTo":"96ed5eac0810170451y69fd864jb44ef62bca468498@mail.gmail.com","subject":"Re: Removing some files from history","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-10-17T12:20:21Z","receivedAt":"2008-10-17T12:20:21Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Please do not toppost, and quote only fragments you are replying to.\n\n\"Gennady Kushnir\" <genkush@rujel.net> writes:\n\n> thank you for precise instructions.\n> \n> however I did not completely understand the part about references\n> and reflog what are these? git tags?\n\ngit-filter-branch saves old version under refs/original/* namespace.\nYou have to remove them after making sure that your rewritten history\nis correct.  \n\nAdditionally git keeps log where branch (tip/head of branch) was in\nyour repository; this is kind of generalization of ORIG_HEAD, and\nallows to recover from such mistakes as wrong \"git reset --hard\".\nReflog entries from your original history also would pin commits, so\nyou have to expire reflog.\n\nAnd finally the commits you have are there in repository, so you have\nto \"prune\" repository to get rid of them.  Reflog entries and\nrefs/original/* pin those commits, so you have to remove them prior to\npruning.  Pruning simply removes objects which are unreferenced.\n\n> and another question:\n> did I understand it right, that I can even make some changes to that\n> file in history - not just simply delete one?\n\nYes, see man git-filter-branch.\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}