se7entyse7en se7entyse7en - 1 year ago 112
Git Question

Git config alias escaping

I'm trying to write a git alias that removes from the commit messages the string "[ci skip]" (placed at the end of the message), but I'm having problem with escaping. The alias takes all the commit from the one passed as argument to


If I run the following command:

git filter-branch -f --msg-filter "sed -e \"s/\[ci skip\]$//g\"" master..HEAD

it works as expected. Anyway if I create the following alias:

unwip = !sh -c 'git filter-branch -f --msg-filter \"sed -e \\\"s/\[ci skip\]$//g\\\"\" $0..HEAD'

and I run
git unwip master
it complains about bad config, but I expect it to behave as the previous commads. How can I fix this?

Answer Source

I'm using bash as a command-line and the following alias worked for me:

unwip = "!f() { git filter-branch --msg-filter 'sed -e "s/[ci skip/]$/g"' $1..HEAD ; }; f"

The only downside is that you're specifying the interpreter and always using sh. In my case I'm relying on user's shell. Though I don't believe it will be a problem in any of major shells as we're doing just basic stuff.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download