16

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?

4
  • Do you get different results from git log -n 1 HEAD and git log -n 1 HEAD^? Commented Mar 7, 2012 at 12:55
  • No, it is the same as described above -- to get the right behaviour I need to use git log -n 1 HEAD^^^^ Commented Mar 7, 2012 at 12:56
  • I found the problem detailed in my answer below. Changed the title to better reflect the problem. Commented Mar 8, 2012 at 10:14
  • Here is HEAD^^ in text, to run .bat in powershell and is echoing and running HEAD^ Commented Apr 7, 2020 at 18:09

5 Answers 5

11

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!

Sign up to request clarification or add additional context in comments.

Comments

1

The ^ is reserved as the escape character in the cmd shell environment. You might have better luck using start-process and passing it in the argument list, but I haven't tested that.

Comments

1

You might be able to use ~ instead of ^

git difftool HEAD~

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

Comments

1

Try escaping the caret with a back-tick: `

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

Comments

0

I don't use git, this is just just an idea, what if you enclose it in quotes?

git difftool "HEAD^"

1 Comment

Yeah I said in the question that I tried that already. Doesn't seem to matter what I enclose it in.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.