Sanford A Staab
Sanford A Staab

Reputation: 43

git shows a weird filename that does not exist

I have no idea how this happened but I am unable to recover from it without chucking my whole local git repository and re-initializing:

$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    "../\357\200\272 ["

no changes added to commit (use "git add" and/or "git commit -a")

$ git diff
diff --git "a/\357\200\272 [" "b/\357\200\272 ["
deleted file mode 100644
index 0bbada91..00000000
--- "a/\357\200\272 ["
+++ /dev/null
@@ -1,238 +0,0 @@
-
-                   SUMMARY OF LESS COMMANDS
-
-      Commands marked with * may be preceded by a number, N.
-      Notes in parentheses indicate the behavior if N is given.
-      A key preceded by a caret indicates the Ctrl key; thus ^K is ctrl-K.
-...

I don't use LESS.

$ git restore --staged "../\357\200\272 ["
error: pathspec '../\357\200\272 [' did not match any file(s) known to git

$ git rm "../\357\200\272 ["
fatal: pathspec '../\357\200\272 [' did not match any files

$ git checkout "../\357\200\272 ["
error: pathspec '../\357\200\272 [' did not match any file(s) known to git

The git version is 2.36.1.windows.1.

Upvotes: 2

Views: 680

Answers (1)

torek
torek

Reputation: 487883

The string that shows up here:

   deleted:    "../\357\200\272 ["

is "quoted", as per core.quotePath:

Commands that output paths (e.g. ls-files, diff), will quote "unusual" characters in the pathname by enclosing the pathname in double-quotes and escaping those characters with backslashes in the same way C escapes control characters (e.g. \t for TAB, \n for LF, \\ for backslash) or bytes with values larger than 0x80 (e.g. octal \302\265 for "micro" in UTF-8). If this variable is set to false, bytes higher than 0x80 are not considered "unusual" any more. Double-quotes, backslash and control characters are always escaped regardless of the setting of this variable. A simple space character is not considered "unusual". Many commands can output pathnames completely verbatim using the -z option. The default value is true.

Running:

git -c core.quotepath=false status

will dump out the name without using the quoting trick. It's not clear what encoding you're using in the first place; it does not appear to be UTF-8 as this would be U+F03A which is in the "private use" area, followed by a space and a left square bracket. However, it does not appear to be CP1252 either, as there we get  [ (Latin small letter I with diaeresis, Euro symbol, and masculine ordinal indicator, followed by space and square bracket).

In any case, as Sam Varshavchik noted in a comment, the file was in your current commit. It is in your current, proposed, commit-to-be-made right now, but it is not in your working tree right now. It looks like a junk file that someone accidentally committed, that should be removed from this and future commits.

It's probably wise to make a commit that does nothing else except remove that file. Simply git add the deletion of the file (use git add -u to do that the easy way), run git status to confirm that it is now in Changes staged for commit, and commit that.

Then, as Sam Varshavchik suggested, consider using git rebase to combine this commit with whichever one added the junk file, if squashing the commits together is acceptable. If not, just keep the deletion commit as a deletion commit.

Upvotes: 3

Related Questions