简体   繁体   中英

Adding file to Git repository

I am trying to add a file from Visual Studio Code to Git repository. But whenever I type this code:

$ git add index.html 

I get this message in my terminal:

fatal: pathspec 'index.html' did not match any files

I thought I typed the file name exactly as it was typed in my finder. Any suggestions?

Well, I imagine you are not in the correct folder. Just go to the folder which contains the file index.html and do these steps:

git add index.html

git commit -m "comment"

git push origin master //or whatever branch you are working in

Some things to try:

git status

This will show you any files that are modified or not yet in the repo (plus other status's), eg:

$ 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

Here you can see there is a file to add in a sub-folder called test. So I can do:

git add test/test12345.txt
git commit -m "added new file"

If you do not see the file that you want to add, check in the .gitignore file on the top level of your git repo. It might contain some sort of pattern to ignore the location of type or name of your file.

First of all let us assume your project name is myApp then at terminal you should be inside the myApp project and from there if you type git status you will get then list of newly added files or new created files from there you add file using command git add "file name along with directory path" but since you are simply adding the file without directory path so you are facing the problem.

I am providing the screenshot as how i have doneaddFilesTOGit

Navigate to the directory where index.html is located or to the root directory of your project. issue git add index.html command or git stage index.html which is equivalent git add * for adding all files that have not been added earlier. Then you can commit and push

git commmit -m "Some commit message here"
git push -u origin master

git add. (it adds all the files to the staging area) git commit -m "message goes here" (commit the code which is staged) git push -u origin master (push all the committed files to the master branch)

if you want to learn more about git, you can find complete git cheatsheethere

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM