我需要为特定的分支进行子树合并,如果它存在于给定的远程存储库中。问题是远程存储库不是在本地签出的,所以我不能使用git branch -r。我所拥有的只是一个远程地址,类似于这个https://github.com/project-name/project-name.git。有没有办法只按远程地址列出远程分支?我找不到任何有用的东西:
发布于 2015-05-29 16:38:37
$ git ls-remote --heads git@github.com:user/repo.git branch-name如果找到branch-name,您将获得以下输出:
b523c9000c4df1afbd8371324083fef218669108 refs/heads/branch-name否则不会发送任何输出。
因此,将其通过管道传输到wc会得到1或0
$ git ls-remote --heads git@github.com:user/repo.git branch-name | wc -l或者,您可以在git ls-remote上设置--exit-code标志,如果找不到匹配的引用,该标志将返回退出代码2。可以直接在shell测试中检查结果,也可以通过检查状态变量$?来检查。
$ git ls-remote --exit-code --heads git@github.com:user/repo.git branch-name发布于 2011-11-22 16:35:38
git ls-remote --heads https://github.com/rails/rails.git
5b3f7563ae1b4a7160fda7fe34240d40c5777dcd refs/heads/1-2-stable
81d828a14c82b882e31612431a56f830bdc1076f refs/heads/2-0-stable
b5d759fd2848146f7ee7a4c1b1a4be39e2f1a2bc refs/heads/2-1-stable
c6cb5a5ab00ac9e857e5b2757d2bce6a5ad14b32 refs/heads/2-2-stable
e0774e47302a907319ed974ccf59b8b54d32bbde refs/heads/2-3-stable
13ad87971cc16ebc5c286b484821e2cb0fc3e3b1 refs/heads/3-0-stable
3df6c73f9edb3a99f0d51d827ef13a439f31743a refs/heads/3-1-stable
f4db3d72ea564c77d5a689b850751ce510500585 refs/heads/compressor
c5a809e29e9213102351def7e791c3a8a67d7371 refs/heads/deps_refactor
821e15e5f2d9ef2aa43918a16cbd00f40c221e95 refs/heads/encoding
8f57bf207ff4f28fa8da4544ebc573007b65439d refs/heads/master
c796d695909c8632b4074b7af69a1ef46c68289a refs/heads/sass-cleanup
afd7140b66e7cb32e1be58d9e44489e6bcbde0dc refs/heads/serializers发布于 2017-08-04 09:59:52
您还可以使用以下命令:
git show-branch remotes/origin/<<remote-branch-name>>返回$的最新提交和值?否则0是否返回"fatal: bad sha1 reference remotes/origin/<>“和$的值?是128
https://stackoverflow.com/questions/8223906
复制相似问题