If you come from a UNIX background, you know how much the Windows command-line sucks (hint: a lot). Powershell is a little bit better, but still, at least in my mind, a far cry from the power & flexibility of bash (or whatever your favorite UNIX shell is). But I digress.
For a while, I was mounting my Windows drives on a real Linux box, and just doing all my Git work on a (ahem) real command line, but I kept running into performance issues, so I finally had to abandon that approach and now I use Powershell to interface with Git. (I’m aware of Cygwin, but something about Cygwin has always rubbed me wrong…I should probably give it another chance at some point.)
Git’s lineage is unsurprisingly and unapologetically founded on Linux, and some of the syntax that UNIX shell users are used to simply do not work on Windows without jumping through some hoops.
I got bit by a very frustrating one today that was essentially “unsearchable”. That is, most search engines do a terrible job of searching for symbols or symbol combinations. I finally figured it out on my own, but I wanted to share the two things you should know if you’re using Git from a Windows-based shell.
Problem #1: the circumflex (^)
Git commits can be referenced in a relative fashion by using the circumflex and the tilde. The circumflex references which parent, whereas the tilde always references the first parent. But I’m not here to explain that distinction to you right now: I’m here to tell you that the circumflex has a special meaning in the standard Windows shell, so saying
git show HEAD^ won’t work. You have to awkwardly escape the circumflex with quotation marks:
git show HEAD"^". Note that this is not an issue in Powershell, which is a lot better than the standard Windows command shell anyway.
Problem #2: the double-dash (–)
This one drove me crazy today. I was trying to find out what commit a file was deleted in, which, as any savvy Git user knows can be accomplished with
git log --online -- deleted.txt. However, I just kept getting the frustrating error message:
PS> git log --oneline -- test.html fatal: ambiguous argument 'test.html': unknown revision or path not in the working tree. Use '--' to separate paths from revisions
But I am using ‘–’ to separate paths from revisions, you stupid machine! It turns out that the Windows shell (as well as Powershell) strip double dashes out for mysterious reasons. So you have to quote them:
PS> git log --oneline "--" test.html eca3ed4 Removed that stupid html file. 10aa506 First commit
And finally it works!