3

我正在尝试使用 shell 函数添加以下别名

scommit = "!f() { git submodule foreach -q --recursive 'git commit -a || :' ; git commit -am \" Update submodule \";}; f"

但是当我在 Git bash 中运行它时(在 Windows 上)

git config --local alias.scommit "!f() { git submodule foreach -q --recursive 'git commit -a || :' ; git commit -am "" Update submodule "";}; f"

我得到了输出

git config --local alias.scommit "fit fetch upstream() { git submodule foreach -q --recursive 'git commit -a || :' ; git commit -am "" Update submodule "";}; f"

当然它不起作用,因为

扩展别名“提交”失败;'fit' 不是 git 命令

我也尝试在 PowerShell 中运行它,但它显示了用法: git config [] ...</p>

当我手动将它添加到 .git/config 时,它就可以工作了。

如何使用 git bash/ 命令行 / PowerShell 添加此别名?为什么会变成fit fetch upstream()?

4

1 回答 1

2

我刚刚在 Windows 10 上使用 Git 2.18 进行了测试:

git config --local alias.scommit '!f() { git submodule foreach -q --recursive "git commit -a" || : ; git commit -am "Update submodule";}; f'

这个想法是颠倒引号:别名外部的强引号( ),内部弱引号()。'"

这样可以避免将 for!解释为历史记录中的扩展命令(如您在此处所见)(尽管set +o histexpand在 git config 命令可能有所帮助之前)

于 2018-08-06T21:27:55.510 回答