Home > database >  git error: fatal: ambiguous argument 'origin/main..pipeline_creation': unknown revision or
git error: fatal: ambiguous argument 'origin/main..pipeline_creation': unknown revision or

Time:12-01

I am working with gitlab. I have a yml file which runs the git command diff. This command shows the difference between the two branches. here is the yml file

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$/'

when i run this in the pipeline i am getting this error:

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>...]'

Locally the command is working fine but when I run it in pipeline its not showing the expected result. Does someone know what am i doing wrong here?

CodePudding user response:

The output if git branch -a shows the cause of the problem: The repo does not have any local branches and it only has one remote branch remotes/origin/pipeline_creation. You need to fetch the main branch first before you can use it in the git diff command:

git fetch --depth=1 origin main
  • Related