简体   繁体   English

REST 完全访问权限:无法将文件添加到 Gitlab 中的存储库

[英]REST-full access: Cannot add file to repository in Gitlab

I tried the following request:我尝试了以下请求:

curl -v -X POST --header "PRIVATE-TOKEN:myPrivateToken" 'url-of-gitlab/api/v3/projects/myProjectId/repository/files?file_path=1.json&branch_name=master&content=thefilecontent&commit_message=ACommitMessage'

However, I invariably get然而,我总是得到

"message":"You can only create files if you are on top of a branch"

in the response.在回应中。 I don't know what's missing from my request.我不知道我的请求缺少什么。 The repository is newly created and I created it through the Gitlab UI.存储库是新创建的,我是通过 Gitlab UI 创建的。 Maybe I need to create a branch first?也许我需要先创建一个分支? Any help would do.任何帮助都可以。 Thank you very much.非常感谢。

The repository is newly created and I created it through the Gitlab UI.存储库是新创建的,我是通过 Gitlab UI 创建的。

A newly created repo (through GitLab or even a simple git init locally) has no branches (and no HEAD).新创建的存储库(通过 GitLab 或什至是本地的简单git init没有分支(也没有 HEAD)。
This is what I describe in " Why do I need to explicitly push a new branch? ".这就是我在“为什么我需要明确推送一个新分支? ”中所描述的。

Maybe I need to create a branch first?也许我需要先创建一个分支?

Yes, you do (at least a master branch)是的,你这样做(至少是一个master分支)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM