Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

git difftool HEAD^

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

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.

Is this a feature of PowerShell, or is my setup wrong somewhere?

like image 978
jonnystoten Avatar asked Mar 07 '12 11:03

jonnystoten


2 Answers

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.cmd is a batch script which wraps git.exe and does some other stuff.

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.

The Lesson Is...

Only use git.exe when using Git for Windows with PowerShell!

like image 93
jonnystoten Avatar answered Sep 25 '22 15:09

jonnystoten


You might be able to use ~ instead of ^

git difftool HEAD~

Note that HEAD^^ is the same as HEAD~2

like image 36
AlBlue Avatar answered Sep 22 '22 15:09

AlBlue