我已经在 Windows 10 上安装了 Git,创建了一个新文件夹并成功执行了 git init,并在同一文件夹中创建了一个名为“test1.html”的文件。 git bash 控制台中的“git add test1.html”命令返回以下错误消息:
致命:路径规范“test1.html”与任何文件都不匹配
执行“ls -la”命令会返回证据,证明 stash 的 .git 子文件夹与我尝试添加的文件一起存在。包含的屏幕截图显示了这样的内容。
有什么问题吗?
最佳答案
首先确认 ls 'test1.html'
确实有效,以防文件名以(不可见的)空格结尾。
然后在 CMD 中尝试相同的 git add
(不使用 git bash),看看问题是否仍然存在。
如phd添加the comments ,使用cat -ETv
,使用 -v 表示“--show-nonprinting
”,您可以通过查看以下内容中的尾随“$
”来查看是否有任何额外空格:
vonc@vclp MINGW64 ~/git/gitw (bubbletea)
$ ls -la | cat -ETv
total 13785$
drwxr-xr-x 1 vonc 197121 0 Jun 12 21:18 .$
drwxr-xr-x 1 vonc 197121 0 Jun 9 00:12 ..$
drwxr-xr-x 1 vonc 197121 0 Jun 13 11:49 .git$
-rw-r--r-- 1 vonc 197121 21 May 29 22:59 .gitattributes$
-rw-r--r-- 1 vonc 197121 88 Jun 10 20:44 .gitignore$
-rw-r--r-- 1 vonc 197121 511 Jun 11 18:41 go.mod$
-rw-r--r-- 1 vonc 197121 7418 Jun 11 18:41 go.sum$
drwxr-xr-x 1 vonc 197121 0 May 30 00:03 internal$
-rw-r--r-- 1 vonc 197121 12428 Jun 10 20:44 main.go$
关于Git Add 命令出现 fatal error : pathspec on existing file,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67954920/