簡體   English   中英

如何從 gitlab 恢復已刪除的遠程分支

[英]How to recover deleted remote branch from gitlab

您好在將develop分支合並到stage分支時,我忘記了在 Gitlab 上,我選中了remove source branch的選項。 所以現在我有本地過時的develop分支,以及我已經合並到開發中的最后一個功能分支(本地),在合並(和刪除) developstage之前。 我該怎么做才能完全恢復已刪除的develop版本?

使用 reflog 提取您的分支所在的提交 SHA1。 然后使用結帳命令。

git reflog
git checkout -b <branchname> <sha1> 

我也這樣做了。 從我在本地沒有的 Gitlab 存儲庫中刪除了其他人的分支,因此“git reflog”沒有幫助。 然后我找到了另一個關於恢復 Github 已刪除分支Git: Recover deleted (remote) branch的答案,它建議您是否使用 JIRA 或類似的東西,它會有一個指向提交的鏈接,並且確實鏈接在那里並點擊它帶來了我有權提交。 該鏈接包含要在@diego-baranowski 答案中使用的提交的 SHA1 id。

git checkout -b <branchname> <sha1>

其中“branchname”可以是您想要的任何名稱,與已刪除的分支名稱或新名稱相同,“sha1”是提交的長 SHA1 id。

或者,您可以使用 curl(或更好)Postman 列出 GitLab 服務器上的事件,並在您執行的“從 SHA1 中刪除的”事件中找到它(也將具有“comid”)。

curl --location --request GET 'https://gitlab.com/api/v4/events' --header 'Authorization: Bearer <your Personal Access Token here>

像這樣返回 JSON:

   {
    "id": xxxx,
    "project_id": xxxx,
    "action_name": "deleted",
    "target_id": null,
    "target_iid": null,
    "target_type": null,
    "author_id": xxxx,
    "target_title": null,
    "created_at": "2021-11-08T20:27:56.299Z",
    "author": xxxx,
    "push_data": {
        "commit_count": 0,
        "action": "removed",
        "ref_type": "branch",
        "commit_from": "<YOUR SHA1 ID IS HERE>",
        "commit_to": null,
        "ref": "<DELETED NAME HERE>",
        "commit_title": null,
        "ref_count": null
    },
    "author_username": "xxxx"
},

暫無
暫無

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

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