【问题标题】:Updating and committing file by using gitlab api使用 gitlab api 更新和提交文件
【发布时间】:2018-01-31 22:20:18
【问题描述】:

我想更新文件内容并提交。为了能够实现,我从 url 中查看了 gitlab 的 api; http://mygitlabadress/help/api/README.md

它说更新现有文件是这样完成的; http://mygitlabadress/help/api/repository_files.md#update-existing-file-in-repository

我按照说明写; http://mygitlabadress/api/v4/projects/:id/repository/files/file1%2Ffile2%2Ftest?ref=master&author_name=name%20surname&content=some%20other%20content&commit_message=update%20file&private_token=:PRIVATE_TOKEN

这返回为; {"file_name":"test","file_path":"file1/file2/test","size":5,"encoding":"base64","content":"ZmRhcwo=","re​​f":"master ","blob_id":"e1afa79f4...","commit_id":"5d61796...","last_commit_id":"5d617962a23c07345e68..."}

但是当我检查主分支上的提交时。提交未完成。我不明白为什么会这样。上述请求不会返回错误。相反,它在提交完成时返回。

我错过了什么?如何更新文件并提交?

【问题讨论】:

    标签: git gitlab commit git-commit gitlab-api


    【解决方案1】:

    看起来您正在发出 GET 请求而不是 PUT。

    你在使用 curl 吗?您应该使用文档中给出的示例curl 请求:

    curl --request PUT --header 'PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK' 'https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject%2Erb?branch=master&author_email=author%40example.com&author_name=Firstname%20Lastname&content=some%20other%20content&commit_message=update%20file'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-28
      • 2019-05-10
      • 2013-10-20
      • 2018-11-17
      • 1970-01-01
      • 1970-01-01
      • 2020-01-23
      • 2022-10-14
      相关资源
      最近更新 更多