简体   繁体   English

查找特定提交的分支并检出该分支

[英]Find a branch of particular commit and checkout to it

How could I easily find a branch with a particular commit and checkout to it with rugged so that I won't end with 'detached HEAD' state? 我如何轻松地找到具有特定提交的分支,并以坚固耐用的方式签出该分支,以使我不会以“分离的HEAD”状态结尾?

Step by step I'd like to: 我想逐步:

  • Clone repository 克隆存储库
  • repo.lookup commithash to return catch exception and exit if Rugged::OdbError: Object not found happens repo.lookup commithash返回捕获异常,如果Rugged::OdbError: Object not found ,则退出
  • find a branch containing given commit hash 查找包含给定提交哈希的分支
  • checkout to that branch 结帐到该分支

I had the same problem but in my case was when I was trying to run a script on CircleCi, so to avoid the error you should run [[ ! -s \\"$(git rev-parse --git-dir)/shallow\\" ]] || git fetch --unshallow 我遇到了同样的问题,但就我而言,是当我尝试在CircleCi上运行脚本时,为避免该错误,应运行[[ ! -s \\"$(git rev-parse --git-dir)/shallow\\" ]] || git fetch --unshallow [[ ! -s \\"$(git rev-parse --git-dir)/shallow\\" ]] || git fetch --unshallow [[ ! -s \\"$(git rev-parse --git-dir)/shallow\\" ]] || git fetch --unshallow , maybe in your case you just should run just git fetch --unshallow and then run the task that you want. [[ ! -s \\"$(git rev-parse --git-dir)/shallow\\" ]] || git fetch --unshallow ,也许在您的情况下,您应该只运行git fetch --unshallow然后运行所需的任务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM