【发布时间】:2022-11-30 20:26:07
【问题描述】:
我正在使用 gitlab。我有一个运行 git 命令 diff 的 yml 文件。此命令显示两个分支之间的差异。这是 yml 文件
image: bitnami/git:latest
stages:
- Test
Test_stage:
tags:
- docker
stage: Test
script:
- echo "test stage started"
- git diff --color=always origin/main..pipeline_creation README.md | perl -wlne 'print
$1 if /^\e\[32m\+\e\[m\e\[32m(.*)\e\[m$/'
当我在管道中运行它时出现此错误:
Created fresh repository.
Checking out e33fa512 as pipeline_creation...
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
$ echo "test stage started"
test stage started
$ git branch -a
* (HEAD detached at e33fa51)
remotes/origin/pipeline_creation
$ git diff main..pipeline_creation README.md
fatal: ambiguous argument 'main..pipeline_creation': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
该命令在本地运行良好,但是当我在管道中运行它时,它没有显示预期的结果。有人知道我在这里做错了什么吗?
【问题讨论】:
-
由于
pipeline_creation似乎是签出的分支,您确定您的工作回购包含origin/main吗?如果使用不带“..”的语法(如git diff --color=always origin/main pipeline_creation README.md),输出是什么? -
仍然得到同样的错误。使用 git diff main..pipeline_creation README.md
-
我已经用 git branch -a 更新了输出
标签: git gitlab yaml gitlab-ci pipeline