git 如何在 GitHub 存储库中创建文件夹?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12258399/
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-10 14:31:44  来源:igfitidea点击:

How do I create a folder in a GitHub repository?

gitgithubgithub-services

提问by Sagar

I want to create a folder in a GitHub repository and want to add files in that folder. How do I achieve this?

我想在 GitHub 存储库中创建一个文件夹,并想在该文件夹中添加文件。我如何实现这一目标?

采纳答案by moopet

Git doesn't store empty folders. Just make sure there's a file in the folder like doc/foo.txt and run git add docor git add doc/foo.txt, and the folder will be added to your local repository once you've committed (and appear on GitHub once you've pushed it).

Git 不存储空文件夹。只需确保文件夹中有一个文件,例如 doc/foo.txt 并运行git add docgit add doc/foo.txt,一旦您提交,该文件夹就会添加到您的本地存储库中(并在您推送后出现在 GitHub 上)。

回答by Sна?ош?а?

You cannot create an empty folder and thenadd files to that folder, but rather creation of a folder must happen together withadding of at least a single file. On GitHub you can do it this way:

您不能创建一个空文件夹,然后将文件添加到该文件夹​​中,而必须在创建文件夹的同时添加至少一个文件。在 GitHub 上,您可以这样做:

  • Go to the folder inside which you want to create another folder
  • Click on New file
  • On the text field for the file name, first write the folder name you want to create
  • Then type /. This creates a folder
  • You can add more folders similarly
  • Finally, give the new file a name (for example, .gitkeepwhich is conventionallyused to make Git track otherwise empty folders; it is not a Git feature though)
  • Finally, click Commit new file.
  • 转到要在其中创建另一个文件夹的文件夹
  • 点击新建文件
  • 在文件名的文本字段上,首先写下您要创建的文件夹名称
  • 然后键入/。这将创建一个文件夹
  • 您可以类似地添加更多文件夹
  • 最后,为新文件命名(例如,.gitkeep通常用于让 Git 跟踪其他空文件夹;尽管它不是 Git 功能)
  • 最后,单击Commit new file

回答by Kien Truong

First you have to clone the repository to you local machine

首先,您必须将存储库克隆到本地计算机

git clone github_url local_directory

Then you can create local folders and files inside your local_directory, and add them to the repository using:

然后你可以在你的 中创建本地文件夹和文件local_directory,并使用以下方法将它们添加到存储库中:

git add file_path

You can also add everything using:

您还可以使用以下方法添加所有内容:

git add .

Note that Git does not track empty folders. A workaround is to create a file inside the empty folder you want to track. I usually name that file empty, but it can be whatever name you choose.

请注意,Git 不会跟踪空文件夹。解决方法是在要跟踪的空文件夹中创建一个文件。我通常命名该文件empty,但它可以是您选择的任何名称。

Finally, you commit and push back to GitHub:

最后,您提交并推送回 GitHub:

git commit
git push

For more information on Git, check out the Pro Gitbook.

有关 Git 的更多信息,请查看Pro Git书籍。

回答by nevosial

For the ones using the web browser, you can do the following:

对于使用网络浏览器的用户,您可以执行以下操作:

  • Once in the master repository, click on Create new file.
  • In the name of file box at the top, enter the name of your folder
  • Use the /key after the name of the folder. Using this forward slash creates the folder
  • You can see a new box appear next to the folder name wherein you can type the name of your file.
  • In the Commit new filebox at the bottom of the page, you can type the description for your file.
  • Select the radio button Commit directly to the masterbranch.
  • Click on the Commit new filebutton
  • You will see the new directory will be created.
  • 进入主存储库后,单击Create new file
  • 在顶部的文件名框中,输入文件夹名称
  • 在文件夹名称后使用/键。使用此正斜杠创建文件夹
  • 您可以看到文件夹名称旁边出现一个新框,您可以在其中键入文件的名称。
  • 在页面底部的提交新文件框中,您可以键入文件的描述。
  • 选择单选按钮Commit direct to the masterbranch
  • 点击Commit new file按钮
  • 您将看到将创建新目录。

回答by J.Doe

Create a new file, and then on the filename use slash. For example

创建一个新文件,然后在文件名上使用斜杠。例如

Java/Helloworld.txt

Java/Helloworld.txt

回答by saurav singh

Actually GitHub does not create an empty folder.

实际上 GitHub 不会创建一个空文件夹。

For example, to create a folder in C:\Users\Username\Documents\GitHub\Repository:

例如,要在 中创建文件夹C:\Users\Username\Documents\GitHub\Repository

  • Create a folder named docs

  • Create a file name index.htmlunder docs

  • Open the GitHub for desktop application

    It will automatically sync, and it will be there.

  • 创建一个名为docs的文件夹

  • index.htmldocs下创建文件名

  • 打开桌面应用程序的 GitHub

    它会自动同步,它会在那里。

回答by Krishnadas PC

Click on new filein github repo online. Then write file name as myfolder/myfilenamethen give file contents and commit. Then file will be created within that new folder.

在线单击github repo 中的新文件。然后写文件名,myfolder/myfilename然后给出文件内容并提交。然后将在该新文件夹中创建文件。

回答by Zuha Karim

To add a new directory all you have to do is create a new folder in your local repository. Create a new folder, and add a file in it.

要添加新目录,您只需在本地存储库中创建一个新文件夹。创建一个新文件夹,并在其中添加一个文件。

Now go to your terminal and add it like you add the normal files in Git. Push them into the repository, and check the status to make sure you have created a directory.

现在转到您的终端并添加它,就像在 Git 中添加普通文件一样。将它们推送到存储库中,并检查状态以确保您已创建目录。

回答by Mohanraj

You just create the required folders in your local repository. For example, you created the appand configdirectories.

您只需在本地存储库中创建所需的文件夹。例如,您创建了appconfig目录。

You may create new files under these folders.

您可以在这些文件夹下创建新文件。

For Git rules:

对于 Git 规则:

  1. First we need to add files to the directory.
  2. Then commit those added files.
  1. 首先,我们需要将文件添加到目录中。
  2. 然后提交那些添加的文件。

Git command to do commit:

用于提交的 Git 命令:

  1. git add app/ config/
  2. git commit
  1. git add app/ config/
  2. git commit

Then give the commit message and save the commit.

然后给出提交信息并保存提交。

Then push to your remote repository,

然后推送到您的远程存储库,

git push origin remote