如何将目录添加到存储库?

How do I add a directory to a repository?

情况是这样的: 如果重要的话,我正在使用 VS-Code 和集成终端。

git clone foo

好的好的。 现在我添加一个文档并保存它。

git add . 
git commit -m "COmment what i did"
git push origin master 

很有魅力


现在我正在处理 .md 文件
在所述文件中我想添加图片。
我想提到像这样的人:

./Images/NameOfThePicture.jpg

在我使用的 VSC 中使用集成终端:

mkdir Images

所以现在有 ./src/Documentation/Images
伟大的!


但是当我现在

git add ./Images
git commit -m "foo"
git push origin master

根本不存在 ./Images 目录。


所以我要找的是

git add ./Images
git commit -m "foo"
git push origin master

不会那么难吧?!


我做了 google 很多事情,但就是没有找到我能立即理解的答案。

非常感谢您的帮助!

无法将文件夹添加到 git,因为文件夹没有差异。 如果您在文件夹中添加文件,则在检出存储库时将创建该文件夹。

由于您要将内容添加到目录中,因此您需要做的就是在该目录中添加文件:

git add ./Images/NameOfThePicture.jpg
git commit -m "Write a meaningful commit message."
git push origin master

正如 Matthieu Brucher 上面所说,空白文件夹没有差异,因此很难添加差异,在这种情况下没有必要。如果您确实编写了一个需要空白文件夹存在的应用程序,则有一些变通方法,但其中大多数会阻止您在该文件夹中包含任何内容。