如何解决GitLab没有看到包含最后提交的分支
在gitlab作业的script
部分中,我想确定触发该作业的提交是否属于某个分支。
$ git branch -a --contains $CI_COMMIT_SHORT_SHA
* (HEAD detached at 460a1f74)
我只看到该提交分离了头部,但是我没有看到我刚刚推送的分支的名称(包含该提交)
然后我运行此命令,但是在本地终端中指定了提交(与上面相同)。
git branch -a --contains 460a1f74
* (HEAD detached at 460a1f74)
deploy-job
remotes/origin/deploy-job
它正确输出分支。
然后我尝试使用gitlab的脚本中同一分支中的较旧的特定提交运行它:
$ git branch -a --contains 460a2f55
* (HEAD detached at 460a2f55)
remotes/origin/deploy-job
它正确输出分支。
为什么在第一种情况下我看不到我的分支?
解决方法
我添加了:
git fetch origin
之前
git branch -a --contains $CI_COMMIT_SHORT_SHA
它解决了这个问题。