【问题标题】:Git alias - multiple shell commands fails on last commandGit 别名 - 多个 shell 命令在最后一个命令上失败
【发布时间】:2015-11-14 06:20:54
【问题描述】:

我有这个 git 别名:

[alias]
# rebase feature branch onto current branch (typically release branch)
rebm = !sh -c 'echo rebasing branch \"$0\" on top of \"$1\" && git checkout \"$0\" && git pull origin \"$0\" && git rebase \"$1\" && git checkout \"$1\" && git merge \"$0\" && echo all done && exit 1'

最后一个命令每次都失败,如果是什么 - 例如:git status,exit 1等。每次我得到最后一个命令的“xyz:找不到命令”。

我在 OSX 上运行它。 控制台输出为:

git rebm featbranch releasebranch
... standard git output ...
featbranch:  exit: command not found
fatal: While expanding alias 'rebm': 'sh -c 'echo rebasing branch "$0" on top of "$1" && git checkout "$0" && git pull origin "$0" && git rebase "$1" && git checkout "$1" && git merge "$0" && echo all done && exit 1'': No such file or directory

【问题讨论】:

  • 将-x添加到别名中,看看git实际运行了什么命令?
  • 不管这里的问题是什么,为了更好的可读性,您是否考虑过编写脚本而不是将所有这些命令内联到别名的定义中?

标签: git macos shell


【解决方案1】:

Adam 给我发了这个 .gitconfig 文件,所以我能够找出原因 - 这是由他的别名中的不可打印字符引起的:

$ cat -v -e -t .gitconfig
rebm = !sh -c 'echo rebasing branch \"$0\" on top of \"$1\" && git checkout \"$0\" && git pull origin \"$0\" && git rebase \"$1\" && git checkout \"$1\" && git merge \"$0\" && echo all done &&M-BM- exit 1'$

所以你现在可以清楚地看到行尾的问题:&&M-BM- exit 1

更多关于这类字符:
https://en.wikipedia.org/wiki/Control_character
https://en.wikipedia.org/wiki/Unicode_control_characters

【讨论】:

    猜你喜欢
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-13
    • 2021-07-13
    • 1970-01-01
    • 2013-01-16
    相关资源
    最近更新 更多