Git配置别名转义 [英] Git config alias escaping

查看:269
本文介绍了Git配置别名转义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试写一个git别名,从提交消息中删除字符串[ci skip](放在消息的末尾),但是我有转义的问题。别名将所有提交作为参数传递给 HEAD



如果我运行以下命令:

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

它的工作原理。无论如何,如果我创建以下别名:

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

,我运行 git unwip master 它抱怨坏配置,但我期望表现为以前的逗号。如何解决这个问题?

解决方案

编辑此解决方案在所有情况下都不起作用。 这里是一种正确的解决方案,适用于所有情况。



我使用 bash 作为命令行,以下别名对我有用:

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

唯一的缺点是您指定了解释器,并始终使用 sh 。在我的情况下,我依靠用户的shell。虽然我不相信这是一个大问题,因为我们只是做基本的东西。


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 HEAD.

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?

解决方案

EDIT This solution doesn't work in all cases. Here is a correct solution which works in all cases.

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.

这篇关于Git配置别名转义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆