通过 API 创建新的 GitHub Enterprise Server 仓库时,您可以指定一个要在创建后应用于仓库的 .gitignore 模板。 .gitignore 模板 API 可列出 GitHub Enterprise Server .gitignore 仓库并从中获取模板。
gitignore 的自定义媒体类型
获取 gitignore 模板时,您可以使用以下自定义媒体类型。
application/vnd.github.VERSION.raw
更多信息请参阅“媒体类型”。
Get all gitignore templates
List all templates available to pass as an option when creating a repository.
get /gitignore/templates
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/gitignore/templates
JavaScript (@octokit/core.js)
await octokit.request('GET /gitignore/templates')
Response
Status: 200 OK
[
"Actionscript",
"Android",
"AppceleratorTitanium",
"Autotools",
"Bancha",
"C",
"C++"
]
Not modified
Status: 304 Not Modified
Notes
Get a gitignore template
The API also allows fetching the source of a single template. Use the raw media type to get the raw contents.
get /gitignore/templates/{name}
参数
Name | Type | In | Description |
---|---|---|---|
accept |
string | header |
Setting to |
name |
string | path |
代码示例
Shell
curl \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/gitignore/templates/NAME
JavaScript (@octokit/core.js)
await octokit.request('GET /gitignore/templates/{name}', {
name: 'name'
})
Default response
Status: 200 OK
{
"name": "C",
"source": "# Object files\n*.o\n\n# Libraries\n*.lib\n*.a\n\n# Shared objects (inc. Windows DLLs)\n*.dll\n*.so\n*.so.*\n*.dylib\n\n# Executables\n*.exe\n*.out\n*.app\n"
}
Not modified
Status: 304 Not Modified