<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Repository files API > 原文:[https://docs.gitlab.com/ee/api/repository_files.html](https://docs.gitlab.com/ee/api/repository_files.html) * [Get file from repository](#get-file-from-repository) * [Get file blame from repository](#get-file-blame-from-repository) * [Get raw file from repository](#get-raw-file-from-repository) * [Create new file in repository](#create-new-file-in-repository) * [Update existing file in repository](#update-existing-file-in-repository) * [Delete existing file in repository](#delete-existing-file-in-repository) # Repository files API[](#repository-files-api "Permalink") **庫文件的 CRUD** **使用此 API 創建,讀取,更新和刪除存儲庫文件** 下表描述了使用[個人訪問令牌](../user/profile/personal_access_tokens.html)可用的不同范圍. | Scope | Description | | --- | --- | | `read_repository` | 允許對存儲庫文件進行讀取訪問. | | `api` | 允許對存儲庫文件進行讀寫訪問. | `read_repository` scope was [introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/23534) in GitLab 11.6. ## Get file from repository[](#get-file-from-repository "Permalink") 允許您接收有關存儲庫中文件的信息,例如名稱,大小,內容. 請注意,文件內容是 Base64 編碼的. 如果可公開訪問該存儲庫,則無需身份驗證即可訪問此端點. ``` GET /projects/:id/repository/files/:file_path ``` ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fmodels%2Fkey%2Erb?ref=master" ``` 響應示例: ``` { "file_name": "key.rb", "file_path": "app/models/key.rb", "size": 1476, "encoding": "base64", "content": "IyA9PSBTY2hlbWEgSW5mb3...", "content_sha256": "4c294617b60715c1d218e61164a3abd4808a4284cbc30e6728a01ad9aada4481", "ref": "master", "blob_id": "79f7bbd25901e8334750839545a9bd021f0e4c83", "commit_id": "d5a3ff139356ce33e37e73add446f16869741b50", "last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d" } ``` Parameters: * `file_path` (必需)-URL 編碼的新文件的完整路徑. 例如 lib%2Fclass%2Erb * `ref` (必填)-分支,標記或提交的名稱 **注意:** `blob_id`是 blob SHA,請參見[存儲庫-從存儲庫獲取 blob](repositories.html#get-a-blob-from-repository) 除了`GET`方法外,您還可以使用`HEAD`來獲取文件元數據. ``` HEAD /projects/:id/repository/files/:file_path ``` ``` curl --head --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fmodels%2Fkey%2Erb?ref=master" ``` 響應示例: ``` HTTP/1.1 200 OK ... X-Gitlab-Blob-Id: 79f7bbd25901e8334750839545a9bd021f0e4c83 X-Gitlab-Commit-Id: d5a3ff139356ce33e37e73add446f16869741b50 X-Gitlab-Content-Sha256: 4c294617b60715c1d218e61164a3abd4808a4284cbc30e6728a01ad9aada4481 X-Gitlab-Encoding: base64 X-Gitlab-File-Name: key.rb X-Gitlab-File-Path: app/models/key.rb X-Gitlab-Last-Commit-Id: 570e7b2abdd848b95f2f578043fc23bd6f6fd24d X-Gitlab-Ref: master X-Gitlab-Size: 1476 ... ``` ## Get file blame from repository[](#get-file-blame-from-repository "Permalink") 允許您接收責備信息. 每個責任范圍包含行和相應的提交信息. ``` GET /projects/:id/repository/files/:file_path/blame ``` ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/13083/repository/files/path%2Fto%2Ffile.rb/blame?ref=master" ``` 響應示例: ``` [ { "commit": { "id": "d42409d56517157c48bf3bd97d3f75974dde19fb", "message": "Add feature\n\nalso fix bug\n", "parent_ids": [ "cc6e14f9328fa6d7b5a0d3c30dc2002a3f2a3822" ], "authored_date": "2015-12-18T08:12:22.000Z", "author_name": "John Doe", "author_email": "john.doe@example.com", "committed_date": "2015-12-18T08:12:22.000Z", "committer_name": "John Doe", "committer_email": "john.doe@example.com" }, "lines": [ "require 'fileutils'", "require 'open3'", "" ] }, ... ] ``` Parameters: * `file_path` (必需)-URL 編碼的新文件的完整路徑. 例如 lib%2Fclass%2Erb * `ref` (必填)-分支,標記或提交的名稱 **注意:** `HEAD`方法僅返回文件元數據,如[從存儲庫](repository_files.html#get-file-from-repository)中[獲取文件中所示](repository_files.html#get-file-from-repository) . ``` curl --head --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/13083/repository/files/path%2Fto%2Ffile.rb/blame?ref=master" ``` 響應示例: ``` HTTP/1.1 200 OK ... X-Gitlab-Blob-Id: 79f7bbd25901e8334750839545a9bd021f0e4c83 X-Gitlab-Commit-Id: d5a3ff139356ce33e37e73add446f16869741b50 X-Gitlab-Content-Sha256: 4c294617b60715c1d218e61164a3abd4808a4284cbc30e6728a01ad9aada4481 X-Gitlab-Encoding: base64 X-Gitlab-File-Name: file.rb X-Gitlab-File-Path: path/to/file.rb X-Gitlab-Last-Commit-Id: 570e7b2abdd848b95f2f578043fc23bd6f6fd24d X-Gitlab-Ref: master X-Gitlab-Size: 1476 ... ``` ## Get raw file from repository[](#get-raw-file-from-repository "Permalink") ``` GET /projects/:id/repository/files/:file_path/raw ``` ``` curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fmodels%2Fkey%2Erb/raw?ref=master" ``` Parameters: * `file_path` (必需)-URL 編碼的新文件的完整路徑. 例如 lib%2Fclass%2Erb * `ref` (必填)-分支,標記或提交的名稱 **注意:**像[從存儲庫中獲取文件](repository_files.html#get-file-from-repository)一樣[,](repository_files.html#get-file-from-repository)您可以使用`HEAD`僅獲取文件元數據. ## Create new file in repository[](#create-new-file-in-repository "Permalink") 這使您可以創建一個文件. 要使用一個請求創建多個文件,請參閱[commits API](commits.html#create-a-commit-with-multiple-files-and-actions) . ``` POST /projects/:id/repository/files/:file_path ``` ``` curl --request POST --header 'PRIVATE-TOKEN: <your_access_token>' --header "Content-Type: application/json" \ --data '{"branch": "master", "author_email": "author@example.com", "author_name": "Firstname Lastname", \ "content": "some content", "commit_message": "create a new file"}' \ "https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject%2Erb" ``` 響應示例: ``` { "file_path": "app/project.rb", "branch": "master" } ``` Parameters: * `file_path` (必需)-URL 編碼的新文件的完整路徑. 例如 lib%2Fclass%2Erb * `branch` (必填)-分支的名稱 * `start_branch` (可選)-從中開始新提交的分支名稱 * `encoding` (可選)-將編碼更改為" base64". 默認為文本. * `author_email` (可選)-指定提交作者的電子郵件地址 * `author_name` (可選)-指定提交作者的姓名 * `content` (必填)-文件內容 * `commit_message` (必填)-提交消息 ## Update existing file in repository[](#update-existing-file-in-repository "Permalink") 這使您可以更新單個文件. 有關通過單個請求更新多個文件的信息,請參見[commits API](commits.html#create-a-commit-with-multiple-files-and-actions) . ``` PUT /projects/:id/repository/files/:file_path ``` ``` curl --request PUT --header 'PRIVATE-TOKEN: <your_access_token>' --header "Content-Type: application/json" \ --data '{"branch": "master", "author_email": "author@example.com", "author_name": "Firstname Lastname", \ "content": "some content", "commit_message": "update file"}' \ "https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject%2Erb" ``` 響應示例: ``` { "file_path": "app/project.rb", "branch": "master" } ``` Parameters: * `file_path` (必需)-URL 編碼的新文件的完整路徑. 例如 lib%2Fclass%2Erb * `branch` (必填)-分支的名稱 * `start_branch` (可選)-從中開始新提交的分支名稱 * `encoding` (可選)-將編碼更改為" base64". 默認為文本. * `author_email` (可選)-指定提交作者的電子郵件地址 * `author_name` (可選)-指定提交作者的姓名 * `content` (必填)-新文件內容 * `commit_message` (必填)-提交消息 * `last_commit_id` (可選)-已知文件的最新提交 ID 如果提交由于任何原因失敗,我們將返回 400 錯誤,并顯示非特定錯誤消息. 提交失敗的可能原因包括: * `file_path`包含`/../` (試圖遍歷目錄); * 新文件內容與當前文件內容相同. 也就是說,用戶嘗試進行空提交; * 在進行文件編輯時,通過 Git 推送更新了分支. 當前,GitLab Shell 具有布爾返回碼,可防止 GitLab 指定錯誤. ## Delete existing file in repository[](#delete-existing-file-in-repository "Permalink") 這使您可以刪除單個文件. 有關通過單個請求刪除多個文件的信息,請參見[commits API](commits.html#create-a-commit-with-multiple-files-and-actions) . ``` DELETE /projects/:id/repository/files/:file_path ``` ``` curl --request DELETE --header 'PRIVATE-TOKEN: <your_access_token>' --header "Content-Type: application/json" \ --data '{"branch": "master", "author_email": "author@example.com", "author_name": "Firstname Lastname", \ "commit_message": "delete file"}' \ "https://gitlab.example.com/api/v4/projects/13083/repository/files/app%2Fproject%2Erb" ``` Parameters: * `file_path` (必需)-URL 編碼的新文件的完整路徑. 例如 lib%2Fclass%2Erb * `branch` (必填)-分支的名稱 * `start_branch` (可選)-從中開始新提交的分支名稱 * `author_email` (可選)-指定提交作者的電子郵件地址 * `author_name` (可選)-指定提交作者的姓名 * `commit_message` (必填)-提交消息 * `last_commit_id` (可選)-已知文件的最新提交 ID
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看