git - 检查“远程”是否确实是 git 远程
问题描述
假设我有一个这样的字符串列表:
remotes/origin/master
remotes/origin
origin/master
origin
如何判断字符串的开头是否是有效的遥控器?例如,
remotes/origin
origin
一般来说,两者都应该是有效的遥控器,对吧?怎么确定呢?
解决方案
好吧,回答实际问题(而不是我从示例中看到的我期望看到的问题):
git config --local --get-regexp "^remote\\.$yourname\\.url" >&- \
&& echo it\'s a remote
应该很好吃。我为常用选项组合提供别名,我在这里使用的是
git config --global alias.grl '!f() { git config --local --get-regexp "${@-.}"; }; f'
所以我实际用于自己工作的测试是
git grl "^remote\\.$yourname\\.url" >&- && echo it\'s a remote
要测试远程跟踪分支名称,我在第一次尝试时回答的问题是
[[ `git rev-parse --symbolic-full-name $anything` = refs/remotes/* ]] \
&& echo it\'s a remote
或者
case `git rev-parse --symbolic-full-name $anything` in
refs/remotes/*) echo yes ;;
esac
如果你不使用bash
.
推荐阅读
- java - 如何调用父类方法
- python - 狮身人面像“警告:autodoc:导入类失败”错误
- react-native - 获取当前在 react native javascript 引擎中执行的 javascript 行以进行调试
- azure - Azure 云静态网站 - 使用 https 将自定义根域映射到 cdn
- angular - 如何以角度调用可观察的方法?
- c++ - 如果返回值是抽象类,如何模拟
- c# - COM:当我将 COM 变量放入方法中时,引用计数器会增加吗?
- ios - UIButton 内的 AspectFit 图像
- rabbitmq - 如何在 helm 图表中添加自定义 go 代码?
- php - 通过 POSTMAN POST 多行