{"thread":{"id":"14986","subject":"git-filter-branch behavior","startedAt":"2008-08-13T16:14:20Z","lastAt":"2008-08-15T15:32:21Z","messageCount":4,"participants":["David Neu","Jonathan Nieder","Michael J Gruber"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"87068","messageId":"e0b44a890808130914oced739cy2aaf54aebfcfcbce@mail.gmail.com","threadId":"14986","inReplyTo":null,"subject":"git-filter-branch behavior","fromName":"David Neu","fromEmail":"david@davidneu.com","sentAt":"2008-08-13T16:14:20Z","receivedAt":"2008-08-13T16:14:20Z","isPatch":false,"sender":{"key":"david@davidneu.com","avatar":null},"body":"All,\n\nRunning\n\ngit-filter-branch --tree-filter 'rm -rf subdir/' -- --all\n\nas shown below seems to leave empty commits\ncorresponding to subdir/ in the tree.  Is this the expected\nbehavior?  If so is there a command to remove the empty\ncommits?  Using git-rebase -i to edit the commit history\nworks, but is a bit tedious on a large tree.\n\nMany thanks!\n\nCheers,\nDavid\n\n***** ***** ***** ***** *****\n\nmkdir test-filter-branch\ncd test-filter-branch\n\necho 'base1' > base.txt\nmkdir subdir\necho 'sub1' > subdir/sub.txt\ngit-init\ngit-add .\ngit-commit -a -m \"Commit 1\"\n\necho 'base2' >> base.txt\ngit-commit -a -m \"Commit 2\"\n\necho 'sub3' > subdir/sub.txt\ngit-commit -a -m \"Commit 3\"\n\necho 'base4' >> base.txt\necho 'sub4' > subdir/sub.txt\ngit-commit -a -m \"Commit 4\"\n\ngit-filter-branch --tree-filter 'rm -rf subdir/' -- --all\n\ngitk &\n"},{"id":"87100","messageId":"Pine.GSO.4.62.0808131533320.10800@harper.uchicago.edu","threadId":"14986","inReplyTo":"e0b44a890808130914oced739cy2aaf54aebfcfcbce@mail.gmail.com","subject":"Re: git-filter-branch behavior","fromName":"Jonathan Nieder","fromEmail":"jrnieder@uchicago.edu","sentAt":"2008-08-13T20:41:42Z","receivedAt":"2008-08-13T20:41:42Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hello,\n\nDavid Neu wrote:\n\n> Running\n> \n> git-filter-branch --tree-filter 'rm -rf subdir/' -- --all\n> \n> as shown below seems to leave empty commits\n> corresponding to subdir/ in the tree.  Is this the expected\n> behavior?  If so is there a command to remove the empty\n> commits?\n\nThe following is probably overkill, but it is what I would do.\nIt's completely untested.  If you'd prefer to do things by hand\ninstead, my only advice is that using grafts with filter-branch\nmight be easier than rebase -i.\n\n-- snipsnip --\n# prune-empty-commits - filter-branch filter to avoid boring commits\n#\n# Usage: git-filter-branch --tree-filter <something> \\\n# \t\t--commit-filter 'prune-empty-commits \"$@\"' -- <refs>\n# Public domain.\n\ninteresting=\n\ntest \"$#\" -eq 1 && interesting=t\n\ncommittree=$1\nshift\n\nfor sha1 in \"$@\"\ndo\n\ttest z\"$sha1\" = z-p && continue\n\tmap \"$sha1\" | while read parent\n\tdo\n\t\tparenttree=$(git log -1 --pretty=format:%T \"$parent\")\n\t\ttest \"$committree\" != \"$parenttree\" &&\n\t\t\tinteresting=t\n\t\ttest -n \"$interesting\" && break\n\tdone\n\ttest \"-n interesting\" && break\ndone\n\ntest -n \"$interesting\" && git commit-tree \"$@\" || skip_commit \"$@\"\n"},{"id":"87106","messageId":"Pine.GSO.4.62.0808131552130.11537@harper.uchicago.edu","threadId":"14986","inReplyTo":"Pine.GSO.4.62.0808131533320.10800@harper.uchicago.edu","subject":"Re: git-filter-branch behavior","fromName":"Jonathan Nieder","fromEmail":"jrnieder@uchicago.edu","sentAt":"2008-08-13T21:00:23Z","receivedAt":"2008-08-13T21:00:23Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Jonathan Nieder wrote:\n\n> # prune-empty-commits - filter-branch filter to avoid boring commits\n> #\n> # Usage: git-filter-branch --tree-filter <something> \\\n> # \t\t--commit-filter 'prune-empty-commits \"$@\"' -- <refs>\n[...]\n> \tmap \"$sha1\" | while read parent\n\nOops - the 'map' function is not passed on to scripts, so one should\nuse this script with \"--commit-filter '. prune-empty-commits'\".\n\n> \ttest \"-n interesting\" && break\n\ns/\"-n interesting\"/-n \"$interesting\"/\n\nSorry about that.\n"},{"id":"87319","messageId":"g847i6$cd4$1@ger.gmane.org","threadId":"14986","inReplyTo":"Pine.GSO.4.62.0808131533320.10800@harper.uchicago.edu","subject":"Re: git-filter-branch behavior","fromName":"Michael J Gruber","fromEmail":"michaeljgruber+gmane@fastmail.fm","sentAt":"2008-08-15T15:32:21Z","receivedAt":"2008-08-15T15:32:21Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Jonathan Nieder venit, vidit, dixit 13.08.2008 22:41:\n> Hello,\n> \n> David Neu wrote:\n> \n>> Running\n>>\n>> git-filter-branch --tree-filter 'rm -rf subdir/' -- --all\n>>\n>> as shown below seems to leave empty commits\n>> corresponding to subdir/ in the tree.  Is this the expected\n>> behavior?  If so is there a command to remove the empty\n>> commits?\n> \n> The following is probably overkill, but it is what I would do.\n> It's completely untested.  If you'd prefer to do things by hand\n> instead, my only advice is that using grafts with filter-branch\n> might be easier than rebase -i.\n> \n> -- snipsnip --\n> # prune-empty-commits - filter-branch filter to avoid boring commits\n> #\n> # Usage: git-filter-branch --tree-filter <something> \\\n> # \t\t--commit-filter 'prune-empty-commits \"$@\"' -- <refs>\n> # Public domain.\n> \n> interesting=\n> \n> test \"$#\" -eq 1 && interesting=t\n> \n> committree=$1\n> shift\n> \n> for sha1 in \"$@\"\n> do\n> \ttest z\"$sha1\" = z-p && continue\n> \tmap \"$sha1\" | while read parent\n> \tdo\n> \t\tparenttree=$(git log -1 --pretty=format:%T \"$parent\")\n> \t\ttest \"$committree\" != \"$parenttree\" &&\n> \t\t\tinteresting=t\n> \t\ttest -n \"$interesting\" && break\n> \tdone\n> \ttest \"-n interesting\" && break\n> done\n> \n> test -n \"$interesting\" && git commit-tree \"$@\" || skip_commit \"$@\"\n\nYou may want to pass the tree to be committed here ;)\nI.e.:\ngit commit-tree $committree \"$@\"\netc.\n\nMichael\n"}]}