我想在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.

其他回答

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

Java / Helloworld.txt

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改变了创建文件夹的方法。

我将告诉你们我是如何创建一个空文件夹并添加文件的。

点击新建 输入您的文件夹名称,不要输入其他任何内容 点击“添加README文件” 点击“创建存储库” 现在克隆您创建的文件夹。 在本地回购中添加文件或文件夹 提交更改。 好了。

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

git clone github_url local_directory

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

git add file_path

你也可以添加所有的东西使用:

git add .

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

最后,你提交并推回GitHub:

git commit
git push

有关Git的更多信息,请参阅Pro Git书籍。