git:检查是否在远程回购中提交xyz? [英] git: check if commit xyz in remote repo?

查看:172
本文介绍了git:检查是否在远程回购中提交xyz?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的本地分支中有一个提交xyz,我想检查它是否包含在远程发布存储库中;我能以一种简单的方式做到这一点吗?我可以克隆远程回购,但我希望有一个更好的+更快的方式。 git ls-remote 看起来很有前途,但对我来说没有任何价值。感谢!

解决方案

我们假设引用远程仓库的远程名为 origin 。在这种情况下,首先使用以下命令更新所有远程跟踪分支:

  git fetch origin 
- 包含
选项来指定 $ b>

> git branch
找出哪个远程分支包含了这个提交:

  git 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 to git 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 commit xyz 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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