我正在尝试将Visual Studio Code中的文件添加到Git存储库。但是每当我输入以下代码时:
$ git add index.html
我在终端中收到此消息:
fatal: pathspec 'index.html' did not match any files
我以为我键入的文件名与在查找程序中键入的文件名完全相同。有什么建议吗?
答案 0 :(得分:1)
好吧,我想您不在正确的文件夹中。 只需转到包含文件index.html的文件夹,然后执行以下步骤:
git add index.html
git commit -m "comment"
git push origin master //or whatever branch you are working in
答案 1 :(得分:0)
可以尝试的一些事情:
git status
这将向您显示仓库中已修改或尚未修改的所有文件(加上其他状态),例如:
$ git status
On branch master
Untracked files:
(use "git add <file>..." to include in what will be committed)
test/test12345.txt <<< File not yet in the repo
在这里您可以看到有一个文件要添加到名为test的子文件夹中。所以我可以做:
git add test/test12345.txt
git commit -m "added new file"
如果没有看到要添加的文件,请检入git存储库顶层的.gitignore
文件。它可能包含某种模式,以忽略文件的类型或名称的位置。
答案 2 :(得分:0)
首先让我们假设您的项目名称为myApp,然后在终端上,您应位于myApp项目中,然后从其中输入 git status ,您将获得新添加文件或新文件的列表。从那里创建文件时,您可以使用命令 git添加“文件名和目录路径” 来添加文件,但是由于您只是添加了不带目录路径的文件,因此遇到了问题。
答案 3 :(得分:0)
导航到index.html所在的目录或项目的根目录。
发出git add index.html
命令或git stage index.html
等效于git add *
来添加之前未添加的所有文件。
然后,您可以提交并推送
git commmit -m "Some commit message here"
git push -u origin master
答案 4 :(得分:-1)
git add .
(它将所有文件添加到暂存区)
git commit -m "message goes here"
(提交已暂存的代码)
git push -u origin master
(将所有已提交的文件推送到master分支)
如果您想进一步了解git,可以找到完整的git备忘单here