git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git-filter-branch behavior

From
Michael J Gruber <michaeljgruber+gmane@fastmail.fm>
Date
Aug 15, 2008, 15:32 UTC
Message-ID
<g847i6$cd4$1@ger.gmane.org>
In-Reply-To
<Pine.GSO.4.62.0808131533320.10800@harper.uchicago.edu>
Jonathan Nieder venit, vidit, dixit 13.08.2008 22:41:
Show 46 quoted lines
> Hello,
> 
> David Neu wrote:
> 
>> Running
>>
>> git-filter-branch --tree-filter 'rm -rf subdir/' -- --all
>>
>> as shown below seems to leave empty commits
>> corresponding to subdir/ in the tree.  Is this the expected
>> behavior?  If so is there a command to remove the empty
>> commits?
> 
> The following is probably overkill, but it is what I would do.
> It's completely untested.  If you'd prefer to do things by hand
> instead, my only advice is that using grafts with filter-branch
> might be easier than rebase -i.
> 
> -- snipsnip --
> # prune-empty-commits - filter-branch filter to avoid boring commits
> #
> # Usage: git-filter-branch --tree-filter <something> \
> # 		--commit-filter 'prune-empty-commits "$@"' -- <refs>
> # Public domain.
> 
> interesting=
> 
> test "$#" -eq 1 && interesting=t
> 
> committree=$1
> shift
> 
> for sha1 in "$@"
> do
> 	test z"$sha1" = z-p && continue
> 	map "$sha1" | while read parent
> 	do
> 		parenttree=$(git log -1 --pretty=format:%T "$parent")
> 		test "$committree" != "$parenttree" &&
> 			interesting=t
> 		test -n "$interesting" && break
> 	done
> 	test "-n interesting" && break
> done
> 
> test -n "$interesting" && git commit-tree "$@" || skip_commit "$@"

You may want to pass the tree to be committed here ;) I.e.: git commit-tree $committree "$@" etc.

Michael
Previous: Jonathan Nieder
Message 4 of 4 in “git-filter-branch behavior”
  1. David NeuAug 13, 2008
  2. Jonathan NiederAug 13, 2008
  3. Jonathan NiederAug 13, 2008
  4. Michael J GruberAug 15, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.