git 如何git添加整个文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44306606/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:00:04  来源:igfitidea点击:

How to git add a whole folder

gitgithub

提问by sledge_909

I'm new to git and I am trying to git add my whole working directory but I receive the error message:

我是 git 的新手,我正在尝试 git add 我的整个工作目录,但我收到错误消息:

fatal: pathspec 'folder' did not match any files.

致命:路径规范“文件夹”不匹配任何文件。

I'm in the working dir when I do this command, what am I doing wrong? Also, is it good practice to commit the whole folder instead of file by file? Thank you

当我执行此命令时,我在工作目录中,我做错了什么?另外,提交整个文件夹而不是一个文件一个文件是一个好习惯吗?谢谢

回答by FallAndLearn

You need to first check if you have added that folder in .gitignore file.

您需要首先检查您是否在 .gitignore 文件中添加了该文件夹。

If not, then just do this.

如果没有,那么就这样做。

git add --all 

or

或者

git add .

回答by Gauthier

My guess is that you are trying to add folderwhile you already are in folder.

我的猜测是您正在尝试添加,folder而您已经在folder.

$ cd my_folder
$ git init
$ git add my_folder # this is not going to work

Instead, add everything in the folder, rather than the folder itself:

相反,添加文件夹中的所有内容,而不是文件夹本身:

$ cd my_folder
$ git init
$ git add .


To your other question, adding whole folders is fine, but only relevant when adding sub-folders. Again, you can't git addthe folder that is your repository (my_folderabove).

对于您的另一个问题,添加整个文件夹很好,但仅在添加文件夹时才相关。同样,您不能访问git add作为您的存储库的文件夹(my_folder如上)。

$ cd my_folder
$ ls
my_subfolder  other_things
$ git add my_subfolder # this is fine

The usual way to add everything in your working tree to your repo is git add ..

将工作树中的所有内容添加到存储库的常用方法是git add ..

回答by Anas Laghouaouta

I think your folder is not under git version control, or you ignored it.
try to run git add -Ato add your folder

我认为您的文件夹不受 git 版本控制,或者您忽略了它。
尝试运行git add -A以添加您的文件夹