簡體   English   中英

TFS Git Rest Api - 如何添加子模塊?

[英]TFS Git Rest Api - how to add submodule?

我正在嘗試通過TFS GIT REST API將子模塊添加到我在 TFS 上的 git 存儲庫中,但到目前為止還沒有運氣。 我創建了新的存儲庫並將 .gitmodules 添加到存儲庫,但無法弄清楚如何添加子模塊文件夾/引用。

這是我嘗試使用 .gitignore、.gitmodules 和名為“SomeTools”的子模塊為初始提交構建的原始請求。

POST http://tfs:8080/tfs/My_Collection/My_Projekt/_apis/git/repositories/TestRepo/pushes?api-version=2.0 HTTP/1.1
Accept: */*
Content-Type: application/json
Host: tfs:8080
Content-Length: 7213

{
    "refUpdates":  [
                       {
                           "name":  "refs/heads/develop",
                           "oldObjectId":  "0000000000000000000000000000000000000000"
                       }
                   ],
    "commits":  [
                    {
                        "changes":  [
                                        {
                                            "newContent":  {
                                                               "content":  *.suo\r\n",
                                                               "contentType":  "rawtext"
                                                           },
                                            "changeType":  "add",
                                            "item":  {
                                                         "path":  "/.gitignore"
                                                     }
                                        },
                                        {
                                            "newContent":  {
                                                               "content":  "[submodule \"SomeTools\"]\n\tpath = SomeTools\n\turl = http://tfs:8080/tfs/My_Collection/My_Projekt/_git/SomeTools\n",
                                                               "contentType":  "rawtext"
                                                           },
                                            "changeType":  "add",
                                            "item":  {
                                                         "path":  "/.gitmodules"
                                                     }
                                        },
                                        {
                                            "newContent":  {
                                                               "content":  "198abf113d8baf48aa55ab1897b30fdb7b23c4cc",
                                                               "contentType":  "rawtext"
                                                           },
                                            "changeType":  "add",
                                            "item":  {
                                                         "path":  "/SomeTools",
                                                         "versionType":  "commit"
                                                     }
                                        }
                                    ],
                        "comment":  "Initial commit."
                    }
                ]
}

我們無法通過pushes REST API實現這一點,它可以創建一個新分支但不能創建子模塊。

似乎您手動創建存儲庫並添加了 .gitmodules 文件,如果是,那么您還需要手動創建submodule文件夾/引用,然后提交 > 推送到 Git 服務器。

最簡單的方法是運行git submodule add命令來添加 Git 子模塊:

假設您有 2 個 Git 存儲庫:

http://server:8080/tfs/DefaultCollection/TeamProjectName/_git/Repo1
http://server:8080/tfs/DefaultCollection/TeamProjectName/_git/Repo2

為 Repo1 添加 git 子模塊:

git clone http://server:8080/tfs/DefaultCollection/TeamProjectName/_git/Repo1

git submodule add http://server:8080/tfs/DefaultCollection/TeamProjectName/_git/Repo2

然后提交更改並推送到 Git 存儲庫。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM