【问题标题】:How can I diff two git branches in bitbucket pipeline如何区分 bitbucket 管道中的两个 git 分支
【发布时间】:2017-03-19 11:28:14
【问题描述】:

背景

我想确保推送分支上的所有提交消息都有时间登录

即。 add readme /spend 5m

问题

我想获取 bitbucket 管道中两个 git 分支之间的提交差异,

这是我的 yaml 管道配置:

pipelines:
  default:
    - step:
        script:
          - git log $BITBUCKET_BRANCH --oneline --not master

$BITBUCKET_BRANCH 是管道正在作用的分支。

但管道在尝试与 master 比较时返回错误

+ git log $BITBUCKET_BRANCH --oneline --not master
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>...]'

注意管道中的设置步骤(这是bitbucket预定义的,我无法更改)

git clone --branch="abdullah-s/bitbucketpipelinesyml-created-online-wit-1489917130851" --depth 50 https://x-token-auth:$REPOSITORY_OAUTH_ACCESS_TOKEN@bitbucket.org/abdullah-s/webook.git $BUILD_DIR;
git reset --hard ac61f080a28428bdd885735374164577a2b0aa43;
git remote set-url origin git@bitbucket.org:abdullah-s/webook.git

在设置的第一个命令中,bitbucket 仅从我的存储库中克隆一个分支

我尝试了什么

我试图拉大师

- git checkout -b master
- git pull origin master
- git log $BITBUCKET_BRANCH --oneline --not master

但出现错误

+ git pull origin master
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

问题

如何比较 bitbucket 管道中的两个分支?

【问题讨论】:

    标签: git bitbucket


    【解决方案1】:

    正如您正确指出的那样,Bitbucket 管道只会克隆触发构建的特定分支。

    因此,RefSpec 将设置为特定分支,您将无法合并或区分其他分支。

    例如,如果构建是在开发分支上触发的,那么将设​​置以下 refspec:

    [remote "origin"]
        url = git@bitbucket.org:xxxxxx
        fetch = +refs/heads/develop:refs/remotes/origin/develop
    [branch "develop"]
        remote = origin
        merge = refs/heads/develop
    

    如果您查看可用的分支,您会看到:

    + git branch -a
    * develop
      remotes/origin/develop
    

    您可以执行以下命令:

    git fetch origin "+refs/heads/*:refs/remotes/origin/*"
    

    拉入所有其他分支/标签

    From bitbucket.org:xxxx/xxxxx
     * [new branch]      master     -> origin/master
     * [new branch]      release    -> origin/release
     * [new tag]         xxxx -> xxxx
    

    【讨论】:

    • 感谢这就像一个魅力!我还将这两个命令添加到我的 bitbucket-pipelines.yml 文件中:- git fetch origin "+refs/heads/*:refs/remotes/origin/*" - git diff --name-status origin/master origin/development 假设要比较的附加分支是“开发”
    • 当我执行git diff master ./someFile.txt 时,我仍然得到fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
    • 这个答案让我从绝望的深渊中解救出来——谢谢!
    • 应该标记为正确答案,非常感谢!
    【解决方案2】:

    我没有您问题的完整答案,只是一个提示:您可以通过将密码存储为 SECRET 环境变量来绕过权限问题,然后在您拉动时将管道识别为您自己。

    https://confluence.atlassian.com/bitbucket/environment-variables-794502608.html

    【讨论】:

    • 我会尝试一下,当我回复它并回复你时,谢谢
    猜你喜欢
    • 2018-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    • 2012-09-03
    • 2011-12-29
    • 1970-01-01
    相关资源
    最近更新 更多