从 devops 最近的工作来看,似乎有“两种方法”可以在 git 中签出分支:使用普通的分支名称,例如dev
,或使用前缀为 的分支名称refs/heads/
,例如refs/heads/dev
。
两者有什么区别?
Jenkins 的 Bitbucket webhook 中的某些 HTTP POST 内容提供refs/head
了分支的 " " 版本。其他 POST 内容给出了“basename”分支。
例如,使用(我认为是)Jenkins 语法从拉取请求 Bitbucket 事件中获取 POST 内容,$.pullRequest.fromRef.id
== /refs/heads/dev
...
和$.pullRequest.fromRef.displayId
==dev
在克隆的存储库中,检出refs/heads/dev
并dev
解析为相同的 SHAID,但它们各自stdout
的 s 不同:
$ git checkout refs/heads/dev
Note: checking out 'refs/heads/dev'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at c320fd1... wip
$ git checkout dev
Switched to branch 'dev'
Your branch is up-to-date with 'origin/dev'.
$ git log --oneline -n 1
c320fd1 wip
前者的stdout
外观与您查看 SHAID 时的外观相同。