I am working with the git filter branch for one specific task. It is using the sed command. When I use simple regex everything is working but for something more complex it is not. Maybe I have mistake in the regex or in the escaping chars. Please help.

git filter-branch -f --msg-filter 'sed -e "s/\[PEM-2233\] Merge branch 'master' of https:\/\/bitbucket\.test\.domain\.com\/rrr\/pem\/hello-world into feature\/PEM-2233-do-acceptance-tests/CHANGED/"' -- --all

The commit message I am trying to catch is

[PEM-2233] Merge branch 'master' of https://bitbucket.test.domain.com/rrr/pem/hello-world into feature/PEM-2233-do-acceptance-tests
  • change sed subcommand separator to # – RomanPerekhrest Nov 1 '17 at 8:49
  • not so pro at it, what is the command for changing? or just sed -e "s#regex#replacement#g" – saferJo Nov 1 '17 at 8:53

You can't nest single quotes. The single quote before master closes the quoted string starting after --msg-filter.

As you can't include single quotes in a single quoted string, you need to end the string and properly escape the quotes:

branch '\'master\'' of http

The issue are the single quotes around 'master'. The first of these quotes will end the single quoted string that starts with sed -e. The quotes themselves will not be passed on to sed.

It's equivalent to the issue with

$ echo '"hello 'user'"'
"hello user"

Change the quoting to

  • '\'master\'' (the string 'master' will be seen as an unquoted string by the shell), or
  • '"'master'"' (the string 'master' will be seen as a double quoted string by the shell).

Also, to avoid the leaning toothpick-syndrome, use another delimiter for the s command:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.