问题描述
在我的本地分支中有一个提交xyz,我想检查它是否包含在远程发布存储库中;我能以一种简单的方式做到这一点吗?我可以克隆远程回购,但我希望有一个更好的+更快的方式。 git ls-remote
看起来很有前途,但对我来说没有任何价值。感谢!
我们假设引用远程仓库的远程名为 origin
。在这种情况下,首先使用以下命令更新所有远程跟踪分支:
git fetch origin
选项来指定
- 包含$ b>
找出哪个远程分支包含了这个提交:
> git branchgit branch -r - -contains xyz
(
-r
表示)如果提交xyz
包含在一个或多个远程跟踪分支中,则会看到如下输出:origin / test-suite
origin / HEAD - >原产地/主产地
原产地/主产地
如果它包含在本地存储库中,远程跟踪分支的输出将为空。但是,如果您的存储库中完全不知道该提交,那么您将收到
格式错误的对象名称
和一则用法消息 - 可能有点混乱,如果你不期望它...I have a commit xyz in my local branch that I want to check if it is included in a remote release repository; can I do that in some easy way? I could clone the remote repo, but I'm hoping for a nicer+faster way.
git ls-remote
seemed promising, but found nothing of value to me there. Thanks!解决方案Let's suppose that the remote that refers to the remote repository is called
origin
. In that case, first update all your remote-tracking branches with:git fetch origin
Now you can use the useful
--contains
option togit branch
to find out which of the remote branches contains that commit:git branch -r --contains xyz
(The
-r
means to only show remote-tracking branches.) If the commitxyz
is contained in one or more of your remote-tracking branches, you'll see output like:origin/test-suite origin/HEAD -> origin/master origin/master
If it's contained in your local repository, but not one of the remote-tracking branches, the output will be empty. However, if that commit isn't known in your repository at all, you'll get the error
malformed object name
and a usage message - perhaps a bit confusing if you're not expecting it...这篇关于git:检查是否在远程回购中提交xyz?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!