git - Git 仅在 GitLab 中记录模棱两可的参数
问题描述
我有两个分支,master 和 turtles,其中海龟领先于 master 一个提交:“我喜欢海龟”。
在 GitLab 中,我有以下.yml
文件,它在创建合并请求时运行,或者通过推送分支合并来更新:
update-doc:
stage: deploy
script:
- echo $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
- 'echo $(git log --abbrev-commit remotes/origin/master)'
- 'echo $(git log --abbrev-commit remotes/origin/master..remotes/origin/${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME})'
- 'echo $(git cherry -v remotes/origin/master remotes/origin/turtles --abbrev=1)'
only:
- merge_requests
正如预期的那样,在我的 Windows 机器和托管 GitLab 的 Linux VM 上运行git log --abbrev-commit remotes/origin/master..remotes/origin/turtles
或在 Git Bash 中返回提交消息“我喜欢海龟”。git cherry -v remotes/origin/master remotes/origin/turtles
但是当.yml
文件运行时它找不到分支remotes/origin/turtles
,我得到以下输出:
$ echo $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
海龟
$ echo $(git log --abbrev-commit remotes/origin/master)
8406e4d 更新 .gitlab-ci.yml
$ echo $(git log --abbrev-commit remotes/origin/master..remotes/ origin/${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME})
致命:不明确的参数 'remotes/origin/master..remotes/origin/turtles':未知修订版或路径不在工作树中。使用 '--' 将路径与修订分开,如下所示: 'git [...] -- [...]'
$ echo $(git cherry -v remotes/origin/master remotes/origin/turtles --abbrev =1)
致命:未知的提交远程/来源/海龟
所以 GitLab 清楚地知道$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
变量中有 turtles 分支,但似乎无法解析 remotes/origin/turtles。我也尝试过不使用 remotes/origin/ 部分,但仍然没有运气。
如何让 GitLab 运行器识别合并请求分支的远程路径?或者是否有另一个 git 命令我可以尝试只显示海龟分支上的提交?
解决方案
在 GitLab CI/CD 中,检出代码的默认策略是使用浅合并获取当前分支,例如git fetch --depth 50 origin $CI_COMMIT_BRANCH
. 这解释了为什么您只看到一个分支。
你可以解决这个问题:
- 通过在 Web UI 中将“Git shallow clone”设置为 0,或者
- 通过设置
GIT_DEPTH: 0
您.gitlab-ci.yml
禁用浅克隆,或 - 通过拉/取您需要的任何其他分支,例如
git fetch origin master
请参阅有关浅层克隆的文档。
推荐阅读
- airflow - Airflow BigQueryOperator:如何将输出数据保存到指定的分区列而不是摄取时间
- spring-boot - 当我发送 JSESSIONID 时,Spring Boot 基本身份验证忽略了授权标头?
- php - docker 容器中未指定应用程序加密密钥
- android - Android Jetpack:如何使用 PagingDataAdapter 在回收器视图中进行多选?
- azure - 使用 dot net 进行 Azure 批处理作业调度
- python - Plotly:如何在构面网格中旋转 yaxis 标题?
- ios - 将名称值对添加到 Firebase 实时数据库中的现有特定键(swift)
- java - 通缉但未调用:Mockito
- kubernetes-ingress - kubernetes-Ingress 资源未按预期工作以使用子域公开 2 个应用程序
- c++ - 具有大量行和列的矩阵的列总和