简体   繁体   English

在PowerShell中使用Git for Windows时使用插入符号(^)

[英]Using a caret(^) when using Git for Windows in PowerShell

I'm using git at the command line with PowerShell, and I'm trying to use something like 我在PowerShell的命令行中使用git,我正在尝试使用类似的东西

git difftool HEAD^

Powershell seems to treat this as if I typed Powershell似乎对待这就像我打字一样

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

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. 有趣的是,连续使用四个git difftool HEAD^^^^似乎可以逃逸到一个,所以git difftool HEAD^^^^可以正常工作,因为我希望git difftool HEAD^可以工作。

I've tried escaping the caret with single quotes, double quotes, grave accents, nothing seems to help. 我尝试用单引号,双引号,严重的口音来逃避插入符号,似乎没有任何帮助。

Is this a feature of PowerShell, or is my setup wrong somewhere? 这是PowerShell的一个功能,还是我的设置错了?

I found the problem, and it was with my setup :( 我发现了问题,这是我的设置:(

I'm using Git for Windows, which provides git.exe in a /bin folder and git.cmd in a /cmd folder. 我使用Git的Windows,它提供git.exe的/ bin文件夹和git.cmd在/ CMD文件夹。 git.cmd is a batch script which wraps git.exe and does some other stuff. git.cmd是一个批处理脚本,它包装git.exe并执行其他一些操作。

Both of these directories were in my PATH, with /cmd coming first, so when I typed git , git.cmd was being run. 这两个目录都在我的PATH中,/ cmd首先出现,所以当我输入gitgit.cmd正在运行。 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 ( ^^ ). 在cmd世界中,通过键入其中两个( ^^ )来转义插入符号。

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. 当使用两个或三个插入符号时,我也不理解错误消息。

The Lesson Is... 课程是......

Only use git.exe when using Git for Windows with PowerShell! 使用Git for Windows和PowerShell时只使用git.exe!

You might be able to use ~ instead of ^ 您可能可以使用〜而不是^

git difftool HEAD~ git difftool HEAD~

Note that HEAD^^ is the same as HEAD~2 注意,HEAD ^^与HEAD~2相同

Try escaping the caret with a back-tick: ` 尝试用后退剔除插入符号:`

PS C:\>"Hello`^"
Hello^

我不使用git,这只是一个想法,如果你用引号括起来怎么办?

git difftool "HEAD^"

The ^ is reserved as the escape character in the cmd shell environment. ^保留为cmd shell环境中的转义字符。 You might have better luck using start-process and passing it in the argument list, but I haven't tested that. 你可能有更好的运气使用start-process并将其传递给参数列表,但我还没有测试过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM