在PowerShell中为Windows使用Git时使用插入符号(^) [英] Using a caret(^) when using Git for Windows in PowerShell
问题描述
我正在使用PowerShell在命令行中使用git,而我正在尝试使用类似的东西
I'm using git at the command line with PowerShell, and I'm trying to use something like
git difftool HEAD^
Powershell似乎将其视为我键入的内容
Powershell seems to treat this as if I typed
git difftool HEAD
所以插入符号不见了.如果我使用插入符号的多个副本,则会收到一个奇怪的错误:
so the caret symbol is gone. If I use multiple copies of the caret, I get a weird error:
git difftool HEAD^^
fatal: ambiguous argument 'HEAD@set': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
有趣的是,连续使用四个插入符号似乎可以减少到一个,因此git difftool HEAD^^^^
的工作与我期望的git difftool HEAD^
一样.
Interestingly, using four carets in a row seems to escape down to one, so git difftool HEAD^^^^
works as I expect git difftool HEAD^
to work.
我尝试用单引号,双引号,重音符号转义插入符号,似乎无济于事.
I've tried escaping the caret with single quotes, double quotes, grave accents, nothing seems to help.
这是PowerShell的功能,还是我的设置在某处错误?
Is this a feature of PowerShell, or is my setup wrong somewhere?
推荐答案
我发现了问题,这与我的设置有关:(
I found the problem, and it was with my setup :(
我正在使用Windows的Git,它在/bin文件夹中提供git.exe
在/cmd文件夹中提供git.cmd
. git.cmd
是一个批处理脚本,其中包装了git.exe
并执行其他一些操作.
I'm using Git for Windows, which provides git.exe
in a /bin folder and git.cmd
in a /cmd folder. git.cmd
is a batch script which wraps git.exe
and does some other stuff.
这两个目录都在我的PATH中,/cmd首先出现,因此当我键入git
时,正在运行git.cmd
.因为这是一个批处理脚本,所以不能使用插入号.在cmd世界中,通过键入两个(^^
)可以使插入符号转义.
Both of these directories were in my PATH, with /cmd coming first, so when I typed git
, git.cmd
was being run. Because this was a batch script the caret could not be used. In the cmd world a caret is escaped by typing two of them (^^
).
我猜想这是需要两次的,所以将四个插入号转义为两个,然后是一个(我不太了解).使用两个或三个插入符号时,我也看不懂错误消息.
I guess that this was somehow being required twice, so four carets would be escaped down to two, then one (I don't really understand this bit). I also don't understand the error message when two or three carets are used.
仅将Git for Windows与PowerShell一起使用时,才使用git.exe!
Only use git.exe when using Git for Windows with PowerShell!
这篇关于在PowerShell中为Windows使用Git时使用插入符号(^)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!