我正在使用以下命令来查明是否localgit 分支与branch-name
存在于我的存储库中。它是否正确?有没有更好的办法?
请注意,我是在脚本内执行此操作。为此我想使用管道命令如果可能的话。
git show-ref --verify --quiet refs/heads/<branch-name>
# $? == 0 means local branch with <branch-name> exists.
当我在搜索引擎上搜索“git 检查分支是否存在”时,我看到的第一个页面是此页面。
我得到了我想要的,但我想提供更新的答案,因为原始帖子是 2011 年的。
git rev-parse --verify <branch_name>
这本质上与接受的答案相同,但您不需要输入“refs/heads/”
所以从 shell 脚本来看,这将是
if [ `git rev-parse --verify main 2>/dev/null` ]
then
...
fi
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)