4

So, we're having this weird issue with Git where a file path got messed up somehow. Here's a screenshot to show what I mean:

Screenshot

The issue is that the second file in the screenshot has "Frontend\UserType.php" (backslash as separator), when it should be "Frontend/UserType.php" (like the top). We're seeing both files for some reason. When I run git ls-files, I get "Frontend\UserType.php" as a file.

My co-worker is using Windows 7 with TortoiseGit, and I'm on Debian and just use git from command line. I'm not sure where the issue first originated, but it's getting to be very frustrating. We've tried deleting the file and pushing but it just keeps coming back somehow.

It has now infected a whole bunch of branches. Does anyone know what the hell is going on? And how we can fix it across multiple branches?

sleske
  • 81,358
  • 34
  • 189
  • 227
scootstah
  • 193
  • 2
  • 11
  • What's the glitch is all about? an all-blanks path component? What happens if you run `ls-tree -r HEAD` against that repository on your Debian box -- does it show you pathnames with "funny" characters, like `\123`? You could try this on your co-worker's Windows machine using plain Git for Windows in the console window. My guess is that a) some directory pathname with non-ASCII characters has been committed, and something managed to further break it (for instance, TortoiseGit is old and non-Unicode-enabled yet). Anyway, we need further info. – kostix Sep 20 '13 at 16:24
  • It looks like a forward slash in the name/path has been replaced with a backslash. Is that what you're referring to? Is your screenshot listing two separate files in your repository? – Gavin Smith Sep 20 '13 at 16:32
  • Sorry, guess I wasn't clear enough. The issue is that the second file in the screenshot has "Frontend\UserType.php", when it should be "Frontend/UserType.php" (like the top). We're seeing both files for some reason. When I run git ls-files, I get "Frontend\\UserType.php" as a file. The blanked out part was in Photoshop to hide project details, however that part of the path is the same in both places and is correct. – scootstah Sep 20 '13 at 17:08
  • Could you explain in more detail how you are trying to delete the file? E.g. have you run "git rm" and "git commit" to remove the file from a branch? – Gavin Smith Sep 20 '13 at 21:02
  • I'd say you should try to remove that `Frontend\\UserType.php` file, literally; possibly using your Debian box to carry out this task. But first make sure that copy of the file does not contain contents newer/more relevant than those of the correct file. – kostix Sep 21 '13 at 23:03

2 Answers2

3

It's hard to say exactly what happened without complete logs. As discussed in the comments, this looks like you committed a file named "Frontend\UserType.php".

Git uses forward slashes ("/") as path separators, and has no problems with a backslash in a file name, so for git this is no problem. It will probably cause havoc if you try to check out on a Windows system.

The best options is probably to clone the repository under Linux/Unix, or possibly using Cygwin, then remove / rename the incorrectly named file. Ideally, you might want to remove them from the history as well (otherwise things might break if an old version is checked out), but this may not be necessary.

sleske
  • 81,358
  • 34
  • 189
  • 227
3

For those interested, we solved the issue by deleting the file across all branches and then pushing all back to remote with the following commands:

git filter-branch --force --index-filter \
  'git rm --cached --ignore-unmatch path/to/file' \
  --prune-empty --tag-name-filter cat -- --all

git push origin --all --force
scootstah
  • 193
  • 2
  • 11