【问题标题】:Can not remove stale branches from Gitlab?无法从 Gitlab 中删除陈旧的分支?
【发布时间】:2021-08-01 21:36:45
【问题描述】:

我有一个 Gitlab 存储库,其中包含我以前没有注意到的陈旧分支。我认为它们是由 Gitlab 在其中一位用户使用内置文件编辑器对存储库进行更改时创建的。它们具有自动生成的名称,类似于 0a9cc10e66e4e7e48bf7a7fc302e5dc25dd21416

问题是,我不知道如何删除这个分支。 当我按下“删除分支”按钮时,Gitlab UI 返回代码400。 git cli 也失败了。

git branch --all

* master
  remotes/origin/0a9cc10e66e4e7e48bf7a7fc302e5dc25dd21416
  remotes/origin/HEAD -> origin/master
  remotes/origin/master

git push origin --delete 0a9cc10e66e4e7e48bf7a7fc302e5dc25dd21416

remote: GitLab: You cannot create a branch with a 40-character hexadecimal branch name.

有没有办法完成这个任务?

【问题讨论】:

  • 有趣。看起来 GitLab 决定禁止此类分支名称,但未能考虑删除推送。 :-)
  • 请改进帖子的标题,以便概括您所描述的问题。它是一个陈旧的分支这一事实是无关紧要的。

标签: git gitlab git-branch


【解决方案1】:

错误响应的原因是主动推送规则。 GitLab 为git push 事件提供自定义挂钩。一个这样的钩子是以下安全检查,默认激活。

默认情况下,GitLab 出于安全目的限制某些格式的分支名称。禁止使用 40 个字符的十六进制名称,类似于 Git 提交哈希。

https://docs.gitlab.com/ee/push_rules/push_rules.html#default-restricted-branch-names

建议的解决方案:删除/替换现有的推送规则。

不过,这是一项高级功能。

所有项目:打开管理区 > 推送规则

仅一个项目:打开项目 > 设置 > 存储库 > 选项卡 »推送规则«

替代方案:使用 API 删除分支。

curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://<your-gitlab-instance>.com/api/v4/projects/<project-id>/repository/branches/<branch-name>"

【讨论】:

    【解决方案2】:

    尝试扩展参考名称:

    git push origin -d refs/heads/0a9cc10e66e4e7e48bf7a7fc302e5dc25dd21416
    

    【讨论】:

    • 我收到了和之前一样的来自 Gitlab 的回复remote: GitLab: You cannot create a branch with a 40-character hexadecimal branch name.
    猜你喜欢
    • 2016-12-28
    • 2021-06-21
    • 1970-01-01
    • 2013-05-23
    • 2013-07-02
    • 2015-05-20
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    相关资源
    最近更新 更多