检查分支是否为空 [英] Check if a branch is empty

查看:73
本文介绍了检查分支是否为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用github API检查分支是否为空?

/repos/:owner/:repo/branches/:branch 返回上一次提交,但是如何检查该提交属于同一个分支还是父分支?

解决方案

如"中所示,查找git分支的父分支",则git分支没有父分支".

一个分支与另一个分支相比可以为空,而与另一个分支相比可以为空:

 -x--x(分支1)\o--o(branch2,branch3) 

在这里,与 branch2 相比, branch3 被认为是空",而与 branch1 相比,则2优先.>

并且没有办法知道是从 branch2 还是 branch1 创建了 branch3 .

使用GitHub API,您需要比较两次提交,可以是两个分支名称:

  GET/repos/:owner/:repo/compare/hubot:branchname...octocat:branchname 

这将使您感兴趣的领域,例如:

 状态":在后面",提前":1,"behind_by":2 

但是该状态仅与另一个分支"有关,而没有简单的方法来知道另一个分支"是否为其父".

Is there a way to check if a branch is empty using the github API?

/repos/:owner/:repo/branches/:branch returns the last commit, but how do I check if the commit belongs to the same branch or the parent branch?

解决方案

As illustrated in "Find the parent branch of a git branch", a git branch has no "parent branch".

A branch can be empty compared to another, and ahead compared to another:

--x--x (branch1)
      \
       o--o (branch2, branch3)

Here, branch3 could be considered "empty" when compared to branch2, and 2 commits ahead when compared to branch1.

And there is no way to know if branch3 was created from branch2 or branch1.

With the GitHub API, you would need to compare two commits, which can be two branch names:

GET /repos/:owner/:repo/compare/hubot:branchname...octocat:branchname

That would give you fields of interest like:

"status": "behind",
"ahead_by": 1,
"behind_by": 2,

But that status is only relative to "another branch", without easy way to know if that "other branch" is its "parent" or not.

这篇关于检查分支是否为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆