代码之家  ›  专栏  ›  技术社区  ›  Adam

如何在git alias(windows上的git bash)中转义上游的大括号@{u}?[更新]

  •  2
  • Adam  · 技术社区  · 7 年前

    我在git配置中使用了以下别名来进行格式化

    $ git config alias.lp '!git log --pretty=format:"%h - %an (%ar): %s"'
    

    它用于其他别名,以下是正确的工作示例:

    $ git config alias.la '!f(){ git lp -20 --author="${1-Baur}"; }; f'
    $ git config alias.lm '!f(){ git lp --grep "${1-strange}"; }; f'
    $ git config alias.lf '!git lp --follow'
    

    但我找不到如何实现alias来查看上游提交的方法。

    这是有效的:

    $ git log --pretty=format:"%h - %an (%ar): %s" HEAD..@{u}
    

    但这不起作用:

    $ git lp HEAD..@{u}
    

    出现错误消息:

    fatal: ambiguous argument 'HEAD..@u': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'
    

    如你所见 HEAD..@{u} 成为 HEAD..@u ,大括号丢失。

    启用后 $ GIT_TRACE=1 :

    $ git lp HEAD..@{u}
    21:17:32.678084 git.c:560               trace: exec: 'git-lp' 'HEAD..@{u}'
    21:17:32.679097 run-command.c:626       trace: run_command: 'git-lp' 'HEAD..@{u}'
    21:17:32.683098 run-command.c:626       trace: run_command: 'git log --pretty=format:"%h - %an (%ar): %s"' 'HEAD..@{u}'
    21:17:32.726084 git.c:328               trace: built-in: git 'log' '--pretty=format:%h - %an (%ar): %s' 'HEAD..@u'
    fatal: ambiguous argument 'HEAD..@u': unknown revision or path not in the working tree.
    Use '--' to separate paths from revisions, like this:
    'git <command> [<revision>...] -- [<file>...]'
    

    我该怎么摆脱花括号 git lp HEAD..@{u} 在windows上的git bash中?

    [更新]
    多亏了 @博士 为了指出linux上没有问题!
    我检查了这个转义问题是否只出现在windows上的git bash上。
    windows上的本地ubuntu和ubuntu没有这个问题。
    但我必须使用windows版本。所以我还在寻找解决办法。

    $ git --version
    git version 2.14.1.windows.1
    
    2 回复  |  直到 7 年前
        1
  •  2
  •   phd    7 年前

    对我有用:

    $ git --version 
    git version 2.11.0
    
    $ git config alias.lp '!git log --pretty=format:"%h - %an (%ar): %s"'
    
    $ git config alias.lp
    !git log --pretty=format:"%h - %an (%ar): %s"
    
    $ git lp HEAD~..@{u}
    fc4c763 - Oleg Broytman (5 weeks ago): Build, Tests(tox): Python 3.7
    
    $ GIT_TRACE=1 git lp @~..@{u}
    15:57:15.464236 git.c:600               trace: exec: 'git-lp' '@~..@{u}'
    15:57:15.464326 run-command.c:350       trace: run_command: 'git-lp' '@~..@{u}'
    15:57:15.465775 run-command.c:350       trace: run_command: 'git log --pretty=format:"%h - %an (%ar): %s"' '@~..@{u}'
    15:57:15.466182 run-command.c:209       trace: exec: '/bin/sh' '-c' 'git log --pretty=format:"%h - %an (%ar): %s" "$@"' 'git log --pretty=format:"%h - %an (%ar): %s"' '@~..@{u}'
    15:57:15.469076 git.c:371               trace: built-in: git 'log' '--pretty=format:%h - %an (%ar): %s' '@~..@{u}'
    15:57:15.471285 run-command.c:350       trace: run_command: 'less'
    15:57:15.471744 run-command.c:209       trace: exec: 'less'
    
        2
  •  1
  •   Adam    7 年前

    最后我在windows上找到了git bash的正确转义

    $ git lp \'HEAD..@{u}\'
    $ git config alias.lu '!git lp \'\'HEAD..@{u}\'\' #'
    $ git lu
    

    对于gitconfig

    [alias]
      lu1 = "!git lp \\'HEAD..@{u}\\'"
    
    推荐文章