24

I recently updated Git to version 2.7.2.windows.1 (I am running Windows 7 64-bit). Since the update, I have been unable to run git add with the -p option on files within a certain directory (or its subdirectories) whose name is _ (an underscore).

git status correctly reports that my file has changes:

PS C:\Users\Carl\www\dl> git status
On branch develop
Your branch is up-to-date with 'origin/develop'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   _/php/class.Menu.php

And I can add the entire file with a simple git add, or by specifying the file by name. But if I try to include the -p or --patch option (both variations produce the same results), Git reports that there are no changes:

PS C:\Users\Carl\www\dl> git add -p .\_\php\class.Menu.php
No changes.

This only happens for files within the _ directory, but it doesn't matter whether I cd into that directory to run the git add command without having to explicitly specify a path with an underscore in it; it still doesn't work:

PS C:\Users\Carl\www\dl\_\php> git add -p .\class.Menu.php
No changes.

I had initially thought this problem was related to a similar one I encountered recently on files within the _ directory, which I asked about here. However, that problem appears to have been related to Posix path conversion in MinGW, whereas this problem occurs whether I use Git Bash, Windows PowerShell, or cmd.exe.

As I said in that previous question, I believe underscores to be valid in file/directory names. Additionally, I am not the owner of the project so I cannot rename the directory or move the file.

Is this a bug in Git? Are there any additional steps I can take to determine what the underlying issue is?

Community
  • 1
  • 1
Carl Fink
  • 434
  • 3
  • 14

2 Answers2

14

Well, I was able to reproduce this, and seems that it is the same POSIX-to-Windows path conversion. ProcessMonitor shows that git (actually, perl run by git) looks for a file C:\Program Files\Git\php\class.Menu.php.

To work this around (at least, that worked for me), according to documentation, you can set the environment variable MSYS_NO_PATHCONV temporarily, like so (in git bash):

MSYS_NO_PATHCONV=1 git add -p _/php/class.Menu.php

(I don't know how to set env variables in windows' cmd/powershell, but that should be possible, too.)

You shouldn't enable MSYS_NO_PATHCONV globally/permanently (e.g. using export in git bash or modifying windows' user/system environment variables in system settings), because that can lead to unwanted effects, and it'll probably break much more things than it'll fix (see this SO comment). Actually, git-windows folks warn against even temporary enabling MSYS_NO_PATHCONV.
Having said that, I'm starting to think that OP's problem is a git-for-windows bug and should be reported as such (might have something to do with the fact that git-add is a binary, but git-add--interactive is a perl script).

Another listed workaround is to double the first slash, like git add -p _//php/class.Menu.php (or does that mean the parameter must start with a double slash?), but that doesn't seem to work due to complex intermediate path conversions, that happen between the invocation of git add and the real file access.

Community
  • 1
  • 1
Roman
  • 6,486
  • 2
  • 23
  • 41
  • To set env variables in windows' cmd: `set MSYS_NO_PATHCONV=1` – Stijn de Witt Mar 13 '16 at 22:32
  • 1
    @StijndeWitt Or open the Control Panel > System > Advanced System Settings > Environment Variables, particularly if you need to set something for all users and not merely your current user. – GalacticCowboy Mar 14 '16 at 13:10
  • @GalacticCowboy Just remember that changes to environment variables in control panel don't show up elsewhere until after a reboot. – Dan Is Fiddling By Firelight Mar 14 '16 at 17:25
  • @DanNeely, usually restarting the particular program is enough, but it might be easier to reboot than to start a program that uses multiple services that would need to be restarted (and are not obviously linked). – Dan Field Mar 14 '16 at 17:35
  • @DanField In the case of git, we're usually talking about a console window (cmd), not a service etc. Very simple to exit and relaunch it. – GalacticCowboy Mar 14 '16 at 18:14
  • @DanField I can't remember ever adding/changing one without a reboot. Most recently trying to use vagrant/etc to create a rails VM and in writing a new installer for an old MFC app. The former was in a console window; restarting the command prompt did nothing. The latter had the app refuse to acknowledge its environment var existed until after rebooting. Needing to test a multi-config installer made the latter hell. With the former I wasted about an hour trying every trick on Superuser/Serverfault to force an update without rebooting, only to get every path doubled for my trouble. – Dan Is Fiddling By Firelight Mar 14 '16 at 18:18
  • 1
    @DanNeely This happens (IIRC) because setting env vars does not affect running processes, and if you launch anything via explorer it will inherit explorers pre-existing environment. I think you can get around that by killing explorer and restarting it (or at worst, log off/log on) – FrozenKiwi Mar 14 '16 at 18:56
  • @DanNeely again, though, we're talking about Git running in a command window, not a service or other long-running/heavyweight process. – GalacticCowboy Mar 14 '16 at 19:03
  • Guys, I hate to interrupt you, but you really shouldn't enable `MSYS_NO_PATHCONV` globally/permanently. I'll update the answer in a minute. – Roman Mar 14 '16 at 23:31
  • Thanks, this is helpful. However, it seems to raise as many questions as it answers. While this works within Git Bash, it doesn't help when I'm using PowerShell. If it try it, PS just reports that `The term 'MSYS_NO_PATHCONV=1' is not recognized…`, which makes sense since PS uses native Windows paths. But that means that the POSIX path conversion that seems to be the culprit when using Git Bash is not implicated in PS. So why am I getting the same results regardless of which shell I use? Is there a completely different issue with PS that coincidentally results in the same errors? – Carl Fink Mar 15 '16 at 16:54
  • 1
    @CarlFink The syntax for setting env variables in PowerShell is different from bash (I guess), hence the error. POSIX-to-Windows path conversion is still in effect in PS. – Roman Mar 15 '16 at 18:55
1

I'd try without that .. Also I've never passed a filename to git add -p. I just make my change and run that as is. I would also check to make sure any changes you're making are in fact being applied to that specific file, and the file is being touched.

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146