我想在GitHub存储库中创建一个文件夹,并想在该文件夹中添加文件。我该如何做到这一点?
当前回答
创建一个新文件,然后在文件名上使用斜杠。例如
Java / Helloworld.txt
其他回答
在文件名字段中使用/来创建文件夹,例如在文件名字段中输入folder1/file1将创建文件夹folder1和文件file1。
原来的答案 您不能创建一个空文件夹,然后将文件添加到该文件夹,而是创建一个文件夹必须同时添加至少一个文件。这是因为git不跟踪空文件夹。
在GitHub上,你可以这样做:
转到要在其中创建另一个文件夹的文件夹 点击新建文件 在文件名的文本字段中,首先写上要创建的文件夹名 然后输入/。这会创建一个文件夹 您可以类似地添加更多文件夹 最后,为新文件命名(例如,.gitkeep,通常用于让Git跟踪空文件夹;但它不是Git的特性) 最后,单击提交新文件。
Git不存储空文件夹。只要确保文件夹中有一个文件,比如doc/foo.txt,然后运行git add doc或git add doc/foo.txt,一旦你提交了,这个文件夹就会被添加到你的本地存储库中(一旦你推送它,它就会出现在GitHub上)。
对于使用浏览器的用户,可以执行以下操作:
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 file box at the bottom of the page, you can type the description for your file. Select the radio button Commit directly to the master branch. Click on the Commit new file button You will see the new directory will be created.
实际上GitHub并不创建空文件夹。
例如,在C:\Users\Username\Documents\GitHub\Repository目录下创建一个文件夹:
创建一个名为docs的文件夹 在docs下创建一个名为index.html的文件 打开桌面应用程序GitHub 它会自动同步,它会在那里。
创建一个新文件,然后在文件名上使用斜杠。例如
Java / Helloworld.txt
推荐文章
- 了解Git和GitHub的基础知识
- 在GitHub上有一个公共回购的私人分支?
- 只用GitHub动作在特定分支上运行作业
- Git合并与强制覆盖
- 是否有一个链接到GitHub下载文件的最新版本的存储库?
- GitHub -致命:无法读取用户名https://github.com':没有这样的文件或目录
- Github:我能看到回购的下载数量吗?
- 如何运行一个github-actions步骤,即使前一步失败,同时仍然失败的工作
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 在GitHub repo上显示Jenkins构建的当前状态
- 如何取消在github上的拉请求?
- HEAD和master的区别
- 在另一个目录中运行操作
- GitHub克隆与OAuth访问令牌
- 我可以在GitHub上对要点进行拉请求吗?