{"thread":{"id":"48696","subject":"How to delete files and directories from git commit history?","startedAt":"2018-06-12T19:50:57Z","lastAt":"2018-06-12T20:36:19Z","messageCount":5,"participants":["Steve Litt","Eckhard Maaß","Christian Couder","Eric Sunshine","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"350011","messageId":"20180612154413.3df64441@mydesk.domain.cxm","threadId":"48696","inReplyTo":null,"subject":"How to delete files and directories from git commit history?","fromName":"Steve Litt","fromEmail":"slitt@troubleshooters.com","sentAt":"2018-06-12T19:44:13Z","receivedAt":"2018-06-12T19:50:57Z","isPatch":false,"sender":{"key":"slitt@troubleshooters.com","avatar":null},"body":"Hi all,\n\nI have git 2.17.1 running on Void Linux 64 bit running the Linux\n4.16.9_1 kernel, not available to the public in any way (yet). I have a\nrepository in my project's working directory, and push to a bare\nrepository on the hard disk.\n\nMy project (call it myproject) had a directory (call it docs/propdir)\nthat was unnecessary for the project, and I've decided I don't want to\noffer the files in that directory as free software. So I need to delete\ndocs/propdir from all commits in the repository. I did the following,\nwhile in my working repository's myproject directory:\n\ngit filter-branch --tree-filter 'rm -rf docs/propdir' HEAD\n\nAfter that command, I could git clone the working repo and then git\ncheckout to a commit stage that used to have the directory and files,\nand they're not there. So far, so good.\n\nBut then I view all filenames from that directory that have ever been\nin the project, as follows:\n\ngit cat-file --buffer --batch-all-objects \\\n --batch-check='%(objecttype) %(objectname)' \\\n | grep ^c | cut -d \" \"  -f 2 \\\n | xargs -n 1 git ls-tree -r | sort | uniq \\\n | grep propdir\n\nThe preceding command lists directory docs/propdir and all the files\nit's ever contained. This makes me uneasy because if the filenames are\nstill there, I wonder if there's a route to get the files with a git\ncommand. Second, I'd prefer that when my repo is exposed to the public,\npeople not know this directory and these files ever existed.\n\nWhat command do I do to remove all mention of doc/propdir and its\nfiles from my git history?\n\nThanks,\n\nSteveT\n\nSteve Litt \nJune 2018 featured book: Twenty Eight Tales of Troubleshooting\nhttp://www.troubleshooters.com/28\n\n\n"},{"id":"350015","messageId":"20180612202509.GA25677@esm","threadId":"48696","inReplyTo":"20180612154413.3df64441@mydesk.domain.cxm","subject":"Re: How to delete files and directories from git commit history?","fromName":"Eckhard Maaß","fromEmail":"eckhard.s.maass@googlemail.com","sentAt":"2018-06-12T20:25:09Z","receivedAt":"2018-06-12T20:25:15Z","isPatch":false,"sender":{"key":"eckhard.s.maass@googlemail.com","avatar":"https://avatars.githubusercontent.com/u/21984134?v=4"},"body":"On Tue, Jun 12, 2018 at 03:44:13PM -0400, Steve Litt wrote:\n> git filter-branch --tree-filter 'rm -rf docs/propdir' HEAD\n...\n> What command do I do to remove all mention of doc/propdir and its\n> files from my git history?\n\nAre you sure that you pruned all branches? I would have expected a\ncommand like \"git filter-branch ... -- --all\" to prune every branch from\nthe directories.\n\nGreetings,\nEckhard\n"},{"id":"350016","messageId":"CAP8UFD38pLbAZce0bS=G62SCeTKvjn2Eao26Dkm5p72CAx3pYw@mail.gmail.com","threadId":"48696","inReplyTo":"20180612154413.3df64441@mydesk.domain.cxm","subject":"Re: How to delete files and directories from git commit history?","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2018-06-12T20:26:50Z","receivedAt":"2018-06-12T20:26:54Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Hi,\n\nOn Tue, Jun 12, 2018 at 9:44 PM, Steve Litt <slitt@troubleshooters.com> wrote:\n\n> My project (call it myproject) had a directory (call it docs/propdir)\n> that was unnecessary for the project, and I've decided I don't want to\n> offer the files in that directory as free software. So I need to delete\n> docs/propdir from all commits in the repository. I did the following,\n> while in my working repository's myproject directory:\n>\n> git filter-branch --tree-filter 'rm -rf docs/propdir' HEAD\n\n[...]\n\n> What command do I do to remove all mention of doc/propdir and its\n> files from my git history?\n\nDid you check the \"CHECKLIST FOR SHRINKING A REPOSITORY\" section of\nthe filter-branch man/help page?\n\nBest,\nChristian.\n"},{"id":"350018","messageId":"CAPig+cSTyz7uG7RJFYKZEcS=+-i_mJh6abT7+ePiNm=D8s3RtQ@mail.gmail.com","threadId":"48696","inReplyTo":"CAP8UFD38pLbAZce0bS=G62SCeTKvjn2Eao26Dkm5p72CAx3pYw@mail.gmail.com","subject":"Re: How to delete files and directories from git commit history?","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-06-12T20:33:09Z","receivedAt":"2018-06-12T20:33:13Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Tue, Jun 12, 2018 at 4:26 PM, Christian Couder\n<christian.couder@gmail.com> wrote:\n> On Tue, Jun 12, 2018 at 9:44 PM, Steve Litt <slitt@troubleshooters.com> wrote:\n>\n>> My project (call it myproject) had a directory (call it docs/propdir)\n>> that was unnecessary for the project, and I've decided I don't want to\n>> offer the files in that directory as free software. So I need to delete\n>> docs/propdir from all commits in the repository. I did the following,\n>> while in my working repository's myproject directory:\n>>\n>> git filter-branch --tree-filter 'rm -rf docs/propdir' HEAD\n>\n>> What command do I do to remove all mention of doc/propdir and its\n>> files from my git history?\n>\n> Did you check the \"CHECKLIST FOR SHRINKING A REPOSITORY\" section of\n> the filter-branch man/help page?\n\nAlso see BFG Repo Cleaner for an alternative.\nhttps://rtyley.github.io/bfg-repo-cleaner/\n"},{"id":"350019","messageId":"xmqqk1r391z5.fsf@gitster-ct.c.googlers.com","threadId":"48696","inReplyTo":"20180612154413.3df64441@mydesk.domain.cxm","subject":"Re: How to delete files and directories from git commit history?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-06-12T20:36:14Z","receivedAt":"2018-06-12T20:36:19Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Steve Litt <slitt@troubleshooters.com> writes:\n\n> But then I view all filenames from that directory that have ever been\n> in the project, as follows:\n>\n> git cat-file --buffer --batch-all-objects \\\n>  --batch-check='%(objecttype) %(objectname)' \\\n>  | grep ^c | cut -d \" \"  -f 2 \\\n>  | xargs -n 1 git ls-tree -r | sort | uniq \\\n>  | grep propdir\n>\n> The preceding command lists directory docs/propdir and all the files\n> it's ever contained....\n\nIn which repository did you run this?  As cat-file's documentation\nclearly states, --batch-all-objects does not *care* about the\nreachability, so even after rewriting the history using\nfilter-branch, as long as you have the original objects before your\nhistory rewrite in the repository, it _will_ see those trees with\npropdir, even if they are now unreachable thanks to your\nfilter-branch.  If you are doing the above in the original (or in a\nlocal clone), try running \"git repack -a -d && git prune\n--expire=now\" after filter-branch.\n"}]}