Git filter-branch commit-filter debugging output

1.1k views Asked by At

I am working on converting a repository from cvs to git. Since cvs treats repository subfolders individually, multiple repositories actually depend on a certain subfolder in the primary repo.

I found what I believe is the exact answer that I need Rewrite history git filter-branch create / split into submodules / subprojects

Unfortunately, when I try to run it, I receive the error

git commit-tree: Syntax error: "(" unexpected
 could not write rewritten commit

I don't know how to debug this issue. I tried to echo variables to the terminal and into files, but did not see any created. How can I print a variable defined inside of the filter definition (either to the terminal or to a file)?

2

There are 2 answers

0
detective0922 On

Actually, the command argument in filter-branch is always evaluated in the shell context using the eval command, so you can add "set -x" in the command argument, then it will print details when the command is executed. For example:

git filter-branch --force --env-filter '
set -x
test="aaa"
echo $test
' --tag-name-filter cat -- --branches --tags

so info like below will be printed:

Rewrite 91e9265bad17dfd71c335bbc4c1a0c422982fc50 (1/1) (1 seconds passed, remaining 0 predicted)    ++ test=aaa
++ echo aaa
aaa

FYI.

0
Levi Haskell On

Git filter-branch commit-filter operates inside a temp directory under ./.git-rewrite (unless -d option points it elsewhere). The script's output is expected to be the sha1 of the new commit making it unsuitable for debug messages. However you can still use error stream for that purpose, for example:

echo $my_var >&2

The >&2 expression redirects output to the error stream that is not consumed by the commit-filter.