【问题标题】:Can't add git alias when using shell function使用shell函数时无法添加git别名
【发布时间】:2019-01-10 20:11:33
【问题描述】:

我正在尝试使用 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"

当然它不起作用,因为

别名'scommit'的扩展失败; 'fit' 不是 git 命令

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

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

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

【问题讨论】:

    标签: git git-bash git-alias


    【解决方案1】:

    我刚刚在 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'
    

    这个想法是反转引号:strong quotes (') 在别名外面,weak quotes (") 在里面。

    这避免了 ! 被解释为历史命令的扩展(就像你 can see here 一样)(尽管 git config 命令之前的 set +o histexpand 可能会有所帮助)

    【讨论】:

      猜你喜欢
      • 2013-11-19
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-15
      • 2013-09-05
      相关资源
      最近更新 更多