Git 不将文件夹推送到 GitHub,仅推送文件夹外的文件

Git not pushing folders to GitHub, only files outside folders

我的机器上有一个本地存储库,当我尝试将它推送到 GitHub 上的远程存储库时,只显示外部文件。

我电脑里的目录是这样的:

然而,它在GitHub上是这样显示的:

只添加了 hello.py 文件。

我 运行 我的终端上的以下内容:

git init
git remote add origin {repourl}
git add .
git commit -m "Initial commit"
git push origin master

(这没有错误) 知道为什么会这样吗?

你添加了吗? (正如其他人指出的那样,假设您确实在目录中有文件)

git add server
git add client
git commit -m 'added the client and server'
git push 

你需要使用

git add .

添加所有新创建的文件。

这与 GitHub 无关。 Git 不跟踪空目录:

From the FAQ:

Can I add empty directories? Currently the design of the Git index (staging area) only permits files to be listed, and nobody competent enough to make the change to allow empty directories has cared enough about this situation to remedy it. Directories are added automatically when adding files inside them. That is, directories never have to be added to the repository, and are not tracked on their own. If you really need a directory to exist in checkouts you should create a file in it. .gitignore works well for this purpose (there is also a tool MarkEmptyDirs using the .NET framework which allows you to automate this task); you can leave it empty or fill in the names of files you do not expect to show up in the directory.

因此,如果您希望它们出现,建议添加 .gitignore 方法。

您提到您已经使用了 git add .,

git add .

这里有 2 个选项为什么不起作用

  1. 此命令将您的所有文件添加到 当前目录 中,因此您可能不在根文件夹中
  2. 如果您使用的是 git <2 的旧版本,git add -A 等同于 git add .


空目录

Git 不会添加空目录,为了添加这些目录,请在这些文件夹中添加一个空文件,然后提交。

惯例是在所需文件夹中添加 .gitkeep

touch client/.gitkeep
touch server/.gitkeep