簡體   English   中英

如何在git別名(Windows上的git-bash)中轉義上游的花括號@ {u}? [更新]

[英]How to escape curly braces @{u} of upstream in git alias (git-bash on windows)? [UPDATED]

我在git config中有以下別名用於漂亮的格式

$ 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'

但是我找不到一種方法來實現別名以查看上游提交。

這有效:

$ 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>...]'

我應該如何在Windows上的git bash中的git lp HEAD..@{u}中轉義花括號?

[UPDATE]
感謝@phd指出linux上沒有問題!
我檢查了這個轉義問題僅在Windows上的git bash上。
Windows上的本機ubuntu和ubuntu沒有此問題。
但是我必須使用Windows版本。 因此,我仍在尋找解決方案。

$ git --version
git version 2.14.1.windows.1

為我工作:

$ 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'

最后,我發現Windows上git-bash的正確轉義

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

對於gitconfig

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM