Shell script "git diff origin/master –name-only" throwing error fatal: ambiguous argument 'master': unknown revision or path not in the working tree

huangapple go评论81阅读模式
英文:

Shell script "git diff origin/master --name-only" throwing error fatal: ambiguous argument 'master': unknown revision or path not in the working tree

问题

The translation of the code portion you provided is:

git diff origin/master --name-only

这是您提供的代码部分的翻译。

英文:

git diff origin/master --name-only

command in my bitbucket pipelines throwing below error. but works good in my local git bash.

fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

I am expectign it to return the files that are changed as of from master brnach. with --name-only it is returning only names of the changes files in my local git bash, but throwing above error in bitbuckt pipelines.

答案1

得分: 2

第一点:错误信息提到 'master' 而非 'origin/master'。检查你 Bitbucket 管道的脚本:你是检查 master 还是 origin/master

第二点:取决于你设置的选项,你的管道可能根本没有 origin/master —— 这可能发生在你指示管道仅使用浅克隆时。

  • 要检查这种情况:

在某个时刻让你的管道运行 git branch -r,你会在管道日志中得到远程分支的列表。还要检查 origin 的 refspec 设置:

git config --get-all remote.orgin.fetch

  • 要修复:

在你的管道中运行 git fetch origin master

如果没有指示如何从 origin 获取分支的 refspec,你可能需要运行:

git fetch origin +master:refs/remotes/origin/master

英文:

First: the error message mentions 'master', not 'origin/master'. Check the script for your bitbucket pipeline: do you check for master or origin/master ?


Second: depending on the options you set, your pipeline may well not have origin/master at all -- this may happen if you instruct your pipeline to only use a shallow clone.

  • To check whether this is the case:

have your pipeline run git branch -r at some point, you will have the list of remote branches in the pipeline log. Also check how the refspec is set for origin:

git config --get-all remote.orgin.fetch
  • To fix it:

run git fetch origin master in your pipeline.

If there is no refspec instructing how to fetch branches from origin, you may need to instead run:

git fetch origin +master:refs/remotes/origin/master

答案2

得分: 0

感谢您的回复 @LeGEC。我已尝试下面的命令,它有效,似乎Bitbucket Pipelines 不会像我们的本地那样有 origin/* 的层次结构。在本地的 Windows 11 机器上使用 VSCode 时,我没有观察到任何这些问题,但在 Bitbucket Pipeline 上,它显示了弹出。

$ git diff --name-only master -- VERSION
英文:

Thanks for the response @LeGEC. I have tried the below command and it worked, seems like bitbucket pipelines won't be having hierarchy like origin/* like our local. In the local Windows11 machine with VSCode I haven't observed any of these issues but on the bitbucket pipeline, it showed it popped out.

$ git diff --name-only master -- VERSION

huangapple
  • 本文由 发表于 2023年5月25日 04:03:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76327039.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定