【问题标题】:git error: fatal: ambiguous argument 'origin/main..pipeline_creation': unknown revision or path not in the working treegit error: fatal: ambiguous argument \'origin/main..pipeline_creation\': 未知版本或路径不在工作树中
【发布时间】: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


【解决方案1】:

git branch -a 的输出显示了问题的原因:repo 没有任何本地分支,它只有一个远程分支 remotes/origin/pipeline_creation。您需要先获取 main 分支,然后才能在 git diff 命令中使用它:

git fetch --depth=1 origin main

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-15
    • 2012-08-29
    • 2017-12-19
    • 2020-07-24
    相关资源
    最近更新 更多