我不知道这是怎么发生的,但如果不放弃我的整个本地 git 存储库并重新初始化,我就无法从中恢复:
$ 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.
-...
我不使用 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
git版本是2.36.1.windows.1。
最佳答案
此处显示的字符串:
deleted: "../\357\200\272 ["
被“引用”,如 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.
运行:
git -c core.quotepath=false status
将转储名称而不使用引用技巧。目前尚不清楚您首先使用什么编码;它似乎不是 UTF-8,因为这将是 U+F03A,位于“私有(private)使用”区域,后跟一个空格和左方括号。然而,它似乎也不是 CP1252,因为我们得到  [
(带有分音符的 pull 丁小写字母 I、欧元符号和阳性序数指示符,后跟空格和方括号)。
无论如何,如 Sam Varshavchik noted in a comment ,该文件曾经位于您当前的提交中。它在您当前的、提议的、即将做出的 promise 中,但它不在您现在的工作树中。它看起来像是某人意外提交的垃圾文件,应该从本次提交和将来的提交中删除。
明智的做法可能是进行一次除了删除该文件之外不执行任何其他操作的提交。只需git add
删除文件(使用git add -u
以简单的方式做到这一点),运行git status
来确认它现在处于Changes staged for commit
中,并提交它。
然后,正如 Sam Varshavchik 建议的那样,如果可以接受将提交压缩在一起,请考虑使用 git rebase 将此提交与添加垃圾文件的提交 merge 。如果不是,则将删除提交保留为删除提交。
关于git 显示一个不存在的奇怪文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73172033/