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

本文翻译自:How do I create a folder in a GitHub repository?

I want to create a folder in a GitHub repository and want to add files in that folder. 我想在GitHub存储库中创建一个文件夹,并想要在该文件夹中添加文件。 How do I achieve this? 我该如何实现?


#1楼

参考:https://stackoom.com/question/PqY7/如何在GitHub存储库中创建文件夹


#2楼

Git doesn't store empty folders . Git不存储空文件夹 Just make sure there's a file in the folder like doc/foo.txt and run git add doc or 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). 只需确保文件夹中有一个文件(如doc / foo.txt),然后运行git add docgit add doc/foo.txt ,提交后该文件夹将被添加到您的本地存储库中(并在GitHub上出现一次您已按下它)。


#3楼

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. 请注意,Git不会跟踪空文件夹。 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. 我通常将该文件命名为empty ,但是可以选择任何名称。

Finally, you commit and push back to GitHub: 最后,提交并推回GitHub:

git commit
git push

For more information on Git, check out the Pro Git book. 有关Git的更多信息,请查阅Pro Git书。


#4楼

You just create the required folders in your local repository. 您只需在本地存储库中创建所需的文件夹。 For example, you created the app and config directories. 例如,您创建了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. 然后提交那些添加的文件。

Git command to do commit: 用Git命令来提交:

  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

#5楼

You cannot create an empty folder and then add files to that folder, but rather creation of a folder must happen together with adding 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, .gitkeep which is conventionally used to make Git track otherwise empty folders; it is not a Git feature though) 最后,给新文件起一个名字(例如, .gitkeep通常用于使Git跟踪否则为空文件夹;不过它不是Git功能)
  • Finally, click Commit new file . 最后,点击提交新文件

#6楼

Create a new file, and then on the filename use slash. 创建一个新文件,然后在文件名上使用斜杠。 For example 例如

Java/Helloworld.txt Java / Helloworld.txt

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值