Ad

Git Removing References From Invalidly, Non-existing, C:\tmp\file.har Named File In Bitbucket

- 1 answer

This question is in regards how to in Git removing references from invalidly, non-existing, c:\tmp\file.har named file in bitbucket

I usually work on linux (where the error do not surface, probably because it is not a reserved OS path/filename, and the checkout simply ignores the file) , but now one of our git users on windows reports when checkout they see;

Untracked files Prevent checkout, please move or commit them before checkout
"Couldn't checkout origin/master invalid path c:\tmp\file.har"

I found in bitbucket somebody has managed to check in such named file, do not ask me how they managed, but it makes GIT checkout , even with --force failing due to the invalidly named file. Normally c:\tmp is not a place we use as a root for checked out projects.

I also tried to make c:\tmp git root, and manually create such named file in tmp, but even so the git commands show above error or similar types of errors.

And if I try do a git rm file.har it returns fatal: pathspec file.har do not match any pages

also tried things like open an IDE and then try do a rollback on all files that GIT shows as deletet because it didn't succed the checkout hence "thinks" they are deleted from disk. Even that fails with a msg that the file is not tracked or has an invalid file name. sometimes the file name is shown in GIT error msg within double quotes sometimes single quotes.

Have tried with git version 2.28 and 2.35.0.windows.1

thank you for any hints how to rectify

Ad

Answer

It sounds like you have a file in the repository called literally c:\tmp\file.har, which is a valid file name containing no path separators on Unix systems. Specifically, the backslashes here are not directory separators and are merely a normal character in the file name. As you've noted, however, using this path name is unkind if folks will be using the repository on Windows.

The best way to solve this is clone the repository on Linux or Windows Subsystem for Linux and then do this:

$ git rm 'c:\tmp\file.har'
$ git commit

Note that you should use single quotes for this. Then, merge that change in and the problem will go away.

You could also try the same commands, but passing --cached to git rm, if you're running in Git Bash on Windows. However, I believe that is unlikely to work because that's a different path on Windows.

If you're having trouble finding the exact file name, you can use git ls-files to see what files Git thinks are present in the index. As long as your file name contains no newlines, that should be sufficient to find the proper file.

Ad
source: stackoverflow.com
Ad