1

After an "unsuccessful" git pull on my local master, an error prevents to switch back to master:

C: repo_folder> git checkout master
error: invalid path '?'

The ? must be because it is a keybase repo.

From another branch where I checked out some files of the last commit:

C: repo_folder> git diff origin/master --compact-summary
 "\004" (gone)                               | 1902  ---------------------------
 some irrelevant stuff                       | (num) -

The removed file "\004" (that was never present in my local) seems to come from some Mac OS (someone might have opened a csv and a temporary file was created when that user did the commit and pushed?).

  • observe that the file that is marked as (gone) is to be removed by git
  • the problem is that the filename has characters that are not compatible with the Windows file system and that the file never existed in my local Windows repo.

If I clone from a Linux platform, I can checkout to master with no problems. However, in Windows, there's no way back to the master branch.

Any ideas on how to solve this issue? (already tried some posts with no success) I can't really understand how it comes git doesn't even allow me to checkout to master. Should I file a bug report?

Alternatively, perhaps I could create a new master branch and get rid of the current one.

EDIT

A clone from Linux helped to identify that the file ? was actually there. This could be checked directly from Windows as well by using the command: git ls-tree origin/master (which was showing the original problematic name "\004")

The accepted answer includes the case where you want to save the content of the file, while in my case I only wanted to get rid of it. So in my case, I have just deleted the file from Linux, committed and pushed the change, and did a git fetch origin master:master to fetch my local master with being checked out in another branch (as I was not able to checkout to master). This finally did the trick and I could checkout to master.

Hope this clarifies to someone with a similar problem.

rellampec
  • 698
  • 6
  • 22
  • 1
    https://brendanforster.com/notes/fixing-invalid-git-paths-on-windows/ – user2864740 Oct 05 '20 at 19:28
  • @Pac0 — that only affects existing files in the WC; this error is because Git can’t create the file(s) to begin with. – user2864740 Oct 05 '20 at 19:29
  • nothing to do with git ignored files as can't really make a `.gitignore` pattern for that filename, and it's not about creating a file... but in git trying to delete an inexisting file named with characters that are invalid in the Windows file system: `"\400"\` – rellampec Oct 05 '20 at 19:34

1 Answers1

4

? (or maybe it's EOT) cannot be used as a filename on Windows. The file will have to be deleted or renamed. You can do this most easily by cloning on a system which does allow ? and making the fix.

If you only have Windows, Fixing Invalid Git Paths on Windows offers a method of renaming the file without checking it out. In brief...

  1. git checkout origin/master -f to get the checkout without the problematic file.
  2. Make a branch.
  3. Add and commit the "deleted" problematic file.
  4. Use git ls-tree HEAD^ to get the ID of the problem file.
  5. Use git cat-file -p <ID> to get the content of the problem file.
  6. Put the content into a new file.
  7. Add and commit.
Schwern
  • 153,029
  • 25
  • 195
  • 336
  • I saw some post with the methods you posted above.... there's no such a thing as a problematic file in my case, but a problematic filename to be removed that does not exist at all in my Windows platform. If I do `git ls-tree HEAD^` on Linux, the file does not appear either, because effectively was a temporary file that someone committed and removed creating this tiny mess. – rellampec Oct 05 '20 at 20:00
  • @rellampec If they removed it, it would not be in the master checkout. Or your master is behind. Check `git ls-files master`, not HEAD. Also check for origin/master. And how was the pull "unsuccessful"? What was the error message? – Schwern Oct 05 '20 at 20:09
  • unfortunately, I can't remember the error message of my pull from Windows, and I cannot reproduce because I created a new branch to work out the problem, for which I'm checked out to that other branch and cannot come back to `master`. `git ls-files master` gives no results on both platforms (from windows/new-branch and linux/master). – rellampec Oct 05 '20 at 20:16
  • hmmm... if I do `windows\new-branch> git ls-tree origin/master` I can see the `blob` of the cursed file `"\004"` – rellampec Oct 05 '20 at 20:18
  • @rellampec It's still there. Make sure the fix was pushed from Linux, and that your origin is up to date with `git fetch origin`. – Schwern Oct 05 '20 at 20:25
  • you're right... if i check in Linux the file is there showing as `?` okay... now I can try the fix. Any ideas on how to prevent others to push things like this? – rellampec Oct 05 '20 at 20:28
  • You could get up a [pre-receive hook on the server](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) to ban incompatible filenames, or a clever .gitignore, or add something similar to the test suite, but that's only for this one specific portability problem. Really the project needs to treat Windows as a first class platform and be regularly tested on Windows with something like [AppVeyor](https://ci.appveyor.com/login). – Schwern Oct 05 '20 at 20:34
  • okay, after removing the file via `Linux`, and pushing, from windows I could do `git fetch origin master:master` and finally could checkout to `master` – rellampec Oct 05 '20 at 20:35
  • @rellampec Glad you got it fixed. – Schwern Oct 05 '20 at 20:35
  • could you please, update, so I can select your answer? I will update the question, so no one gets lost with the real scenario (the file was actually there) – rellampec Oct 05 '20 at 20:37
  • @rellampec Sorry, what needs to be updated? The answer assumes the file is in origin/master, as was the case or the pull would not have failed. – Schwern Oct 05 '20 at 20:40
  • all good, made an update to clarify the real context and final resolution and left the rest so someone perceiving things the same way in that moment can get to the answer. – rellampec Oct 05 '20 at 20:50
  • After 1st step I get `error: invalid path` again – Fernando V Feb 23 '22 at 20:37