git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* help with git filter-branch
@ 2010-03-18 14:43 Yann Simon
  2010-03-18 15:19 ` Johannes Sixt
  0 siblings, 1 reply; 2+ messages in thread
From: Yann Simon @ 2010-03-18 14:43 UTC (permalink / raw)
  To: git

Hi,

I am trying to use the script found on the following page:
http://ebixio.com/blog/2009/10/15/git-filter-branch-incantations/

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

I am using git version 1.7.0.2.

Any help appreciated!
Thank you
Yann

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: help with git filter-branch
  2010-03-18 14:43 help with git filter-branch Yann Simon
@ 2010-03-18 15:19 ` Johannes Sixt
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Sixt @ 2010-03-18 15:19 UTC (permalink / raw)
  To: Yann Simon; +Cc: git

Yann Simon schrieb:
> 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-03-18 15:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-18 14:43 help with git filter-branch Yann Simon
2010-03-18 15:19 ` Johannes Sixt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).