我正在使用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[me[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>...]'
本地命令工作正常,但当我在管道中运行它时,它没有显示预期的结果。有人知道我做错了什么吗?
git branch -a
的输出显示了问题的原因:repo没有任何本地分支,只有一个远程分支remotes/origin/pipeline_creation
。您需要先获取main
分支,然后才能在git diff
命令中使用它:
git fetch --depth=1 origin main