如何在 GitHub 上上传子文件夹
How to upload sub folders on GitHub
如何在我创建存储库后上传 GitHub 上的文件夹,我需要在我的存储库中上传一个文件夹?我将如何使用 git-bash 或从终端执行此操作?
我已通过
之类的命令将文件夹添加到 git
$ git add <folder name>
在这种情况下,您想要 push
一个空文件夹。在推送到 remote
存储库之前,您需要向 .gitignore
之类的文件夹添加一些内容。
如果您添加 remote
存储库,只需执行以下步骤
git add <folder name>
git commit -m "a commit message"
git push -u origin master
如果不是先添加 remote
存储库,然后执行步骤 1 到 3:
git remote add origin <repository url with a .git at the end>
Git不支持添加空文件夹
但是您可以在文件夹中创建 .gitignore 或 .gitkeep 或任何其他隐藏文件并添加它。
根据 Git 文档,目前 Git 索引(暂存区)的设计只允许列出文件,没有人有能力做出允许空目录的更改。足以解决这种情况。在其中添加文件时,目录会自动添加。也就是说,目录永远不必添加到存储库中,也不会自行跟踪。
请参阅此了解更多信息:https://git.wiki.kernel.org/index.php/GitFaq#Can_I_add_empty_directories.3F
您可以选择在目录中创建 .gitignore 或 .gitkeep 文件。
有关详细信息,请参阅此内容:How can I add an empty directory to a Git repository?
Git 不支持创建空 sub-folders.
如何在我创建存储库后上传 GitHub 上的文件夹,我需要在我的存储库中上传一个文件夹?我将如何使用 git-bash 或从终端执行此操作?
我已通过
之类的命令将文件夹添加到 git$ git add <folder name>
在这种情况下,您想要 push
一个空文件夹。在推送到 remote
存储库之前,您需要向 .gitignore
之类的文件夹添加一些内容。
如果您添加 remote
存储库,只需执行以下步骤
git add <folder name>
git commit -m "a commit message"
git push -u origin master
如果不是先添加 remote
存储库,然后执行步骤 1 到 3:
git remote add origin <repository url with a .git at the end>
Git不支持添加空文件夹
但是您可以在文件夹中创建 .gitignore 或 .gitkeep 或任何其他隐藏文件并添加它。
根据 Git 文档,目前 Git 索引(暂存区)的设计只允许列出文件,没有人有能力做出允许空目录的更改。足以解决这种情况。在其中添加文件时,目录会自动添加。也就是说,目录永远不必添加到存储库中,也不会自行跟踪。
请参阅此了解更多信息:https://git.wiki.kernel.org/index.php/GitFaq#Can_I_add_empty_directories.3F
您可以选择在目录中创建 .gitignore 或 .gitkeep 文件。
有关详细信息,请参阅此内容:How can I add an empty directory to a Git repository?
Git 不支持创建空 sub-folders.