本文介绍了使用GitHub API创建文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用其API 在git存储库中创建新文件夹?是否可以使用 Trees API 做到这一点?

Is there any way to create a new folder in git repository using their API? Is it possible to do this with Trees API?

推荐答案

是的,但是您需要在目录中创建文件,因为git只跟踪其中包含文件的目录.

Yes, but you'd need to create a file in the directory because git only tracks directories with files in them.

示例:

假设我们有一个名为"foo"的用户,该用户有一个名为"bar"的存储库.回购包含以下内容:

Say we have a user called "foo" who has a repo called "bar". The repo has the following contents:

├── LICENSE
├── main.go
├── main_test.go
└── README.md

如果要在examples目录中创建一个名为example.go的文件,我们将发出以下请求:

If we want to create a file in the examples directory called example.go, we would issue the following request:

PUT /repos/foo/bar/contents/examples/example.go

创建新文件的请求模板如下:

The template for the request to create new files is as follows:

PUT /repos/:owner/:repo/contents/:path

请参见 http://developer.github.com/v3/repos/contents/#创建文件

这篇关于使用GitHub API创建文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 01:08