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

Re: help with git filter-branch

From
Johannes Sixt <j.sixt@viscovery.net>
Date
Mar 18, 2010, 15:19 UTC
Message-ID
<4BA2446F.1080002@viscovery.net>
In-Reply-To
<551f769b1003180743n2b2dde99laf00aa9bfe0141bf@mail.gmail.com>
Yann Simon schrieb:
Show 24 quoted lines
> The idea is to add a missing parent to a certain commit.
> I wrote the following bash script:
> 
> #!/bin/sh
> die () {
>     echo >&2 "$@"
>     exit 1
> }
> [ "$#" -eq 3 ] || die "usage: add_parent <commit_to_update>
> <present_parent> <parent_to_add>"
> git filter-branch --parent-filter \
>     'test $GIT_COMMIT = $1 && \
>     echo "-p $2 -p $3" \
>     || cat' \
>     --tag-name-filter 'cat' \
>     $2..master
> 
> When I try to use it an a test repository, I get the following error:
> 
> ./add_parent.sh ad12d20974cad91ddedd055f5335b7471e48dd1d
> 1541f3ae456556edc7e15cead1ae76f470961be0
> 88b5d6f190f9d7135148c67c4d949c0c06e179ff
> Rewrite ad12d20974cad91ddedd055f5335b7471e48dd1d (1/1)test: 3: =:
> argument expected

The $1, $2, $3 are expanded too late in your script, namely when the --parent-filter is evaluated, not when it is passed as argument to filter-branch. Make it

git filter-branch --parent-filter "
	test \$GIT_COMMIT = $1 &&
	echo -p $2 -p $3 ||
	cat" \
	--tag-name-filter cat \
	$2..master

Of course, you can achieve this particular task slightly easier using a graft as the manual of filter-branch shows.

-- Hannes
Previous: Yann Simon
Message 2 of 2 in “help with git filter-branch”
  1. Yann SimonMar 18, 2010
  2. Johannes SixtMar 18, 2010

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.