[英]How to escape curly braces @{u} of upstream in git alias (git-bash on windows)? [UPDATED]
[英]How to escape { in git alias
我正在嘗試寫日志別名
git config --global --replace-all alias.lol6 "! f() { echo "\$1"; git --no-pager log --oneline --graph -15 \${@}; }; f"
並像這樣使用它:
git lol5 '@{-1}'
git log '@{-1}' #works
但是傳遞給git的commit-ish是@ -1
fatal: ambiguous argument '@-1': unknown revision or path not in the working tree
我讀了這篇文章,但不知道如何使用
謝謝波阿斯
更多信息,嘗試過@vonc advisor
git config --global --replace-all alias.lol6 '! f() { echo "$1"; git --no-pager log --oneline --graph -15 ${@}; }; f'
得到了相同的結果,請打開GIT_TRACE
git lol6 @{-1}
20:20:37.454153 git.c:576 trace: exec: git-lol6 '@{-1}'
20:20:37.454153 run-command.c:640 trace: run_command: git-lol6 '@{-1}'
20:20:37.463150 run-command.c:640 trace: run_command: ' f() { echo "$1"; git --no-pager log --oneline --graph -15 ${@}; }; f' '@{-1}'
@-1
22:20:37.607150 git.c:344 trace: built-in: git log --oneline --graph -15 @-1
fatal: ambiguous argument '@-1': unknown revision or path not in the working tree.
Git在第一個參數周圍添加''
但是!!!,如果我嘗試過
git lol6 HEAD
20:30:35.621257 run-command.c:640 trace: run_command: ' f() { echo "$1"; git --no-pager log --oneline --graph -15 ${@}; }; f' HEAD
Git沒有在HEAD周圍添加''
我更喜歡使用字符串引號'
而不是雙引號:在您的情況下,可以減少轉義。
看到這個例子,在git bash會話中完成。
vonc@voncavn7:/mnt/d/git/git$
git config --global --replace-all alias.lol6 \
'! f() { echo "$1"; git --no-pager log --oneline --graph -15 ${@}; }; f'
首先,我檢查是否可以打印偽造的參數:
vonc@voncavn7:/mnt/d/git/git$ git config --global --replace-all alias.lol6 '! f() { echo "$1"; git --no-pager log --oneline --graph -15 ${@}; }; f'
vonc@voncavn7:/mnt/d/git/git$ git lol6 e
e
fatal: ambiguous argument 'e': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
然后,我嘗試在調用別名時不加引號: git lol6 @{-1}
vonc@voncavn7:/mnt/d/git/git$ git lol6 @{-1}
@{-1}
* 29533fb168 (tmp2) RelNotes: the eleventh batch
* dc8fb4dd7e Merge branch 'rb/quick-install-doc'
|\
| * 65289e9dcd install-doc-quick: allow specifying what ref to install
如果上面的別名/命令不起作用,請始終使用簡化的PATH仔細檢查:
set G=c:\path\to\latest\git
set PATH=%G%\bin;%G%\usr\bin;%G%\mingw64\bin
set PATH=%PATH%;C:\windows\system32;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\
使用“簡化的路徑”-它的工作原理。
現在是什么意思? 為什么有效?
之所以起作用,是因為它沒有告訴您原始PATH, C:\\Windows\\System32
和其他放置在 Git 之前的文件夾中的內容,並且掩蓋了某些Git可執行文件。
我如何也可以使標准的Git安裝工作?
只需使用您自己的Git當前安裝路徑替換上面的c:\\path\\to\\latest\\git
。
然后設置您的PATH
:
set PATH=%G%\bin;%G%\usr\bin;%G%\mingw64\bin
接下來,從原始%PATH%
添加所有其他文件夾,並始終以C:\\windows\\system32;C:\\windows\\System32\\Wbem;C:\\windows\\System32\\WindowsPowerShell\\v1.0\\
。
這樣,您:
git/bin
, git/usr/bin
, git/ming64/bin
)開始,確保Git按預期工作 C:\\windows\\system32\\...
路徑) 通過從最具體到最一般,可以降低已安裝軟件的“意外行為”的發生率。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.