git - Find out if integration branch contains tip of local branches
问题描述
I want to get a list of branches I can safely delete. My question is, is there a way to determine if remotes/origin/dev
contains a commit, without checking out that branch?
git fetch origin;
git branch | while read branch; do
if [ "remotes/origin/dev" --contains "$b" ]; then
echo "$b";
fi
done
How to check if remotes/origin/dev
contains the latest commit of a given branch? Can I avoid checking out remotes/origin/dev
first?
解决方案
利用:
if git merge-base --is-ancestor $b refs/remotes/origin/dev; then
echo $b
fi
但不要git branch
用于这个!改用git for-each-ref
:
git fetch origin
git for-each-ref --format='%(refname)' refs/heads | while read b; do
git merge-base --is-ancestor $b refs/remotes/origin/dev && echo ${b#refs/heads/}
done
例如。(这对所有内容都使用全名,以防万一,但仍会发出缩短的名称。)
问题:
- 分支 B 是否包含提交 C?
(对于某些分支名称/标识符B,包括远程跟踪名称和提交哈希或其他标识符C)实际上是git merge-base
命令回答的另一个更一般的问题的子集。
更普遍的问题是:
- 提交 C1 是提交 C2 的祖先吗?
其中“祖先”允许平等。这是git merge-base --is-ancestor C1 C2
执行的测试。请注意,这些项目中的任何一项都可能是哈希 ID 或引用名称,结果是退出状态的一部分(足够恰当)。该--is-ancestor
测试是 Git 1.8.0 中的新测试。
推荐阅读
- python - 为什么这个程序不异步运行?
- ios - 从firebase获取数据时出现EXC_BAD_ACCESS错误
- java - 如何访问 viewPager 中的按钮
- oracle - 来自 ColdFusion 的 oracle.sql.TIMESTAMP 上的异常调用方法 timestampValue()
- php - 在不应该有输出的函数中使用输出缓冲是否有陷阱?
- python - 提到机器人时如何获取服务器的前缀?不和谐.py
- python - 用条件随机化
- html - 当鼠标悬停在三角形上时,如何使 2 个按钮出现?
- java - Gradle maven 发布插件在多模块项目中失败,并出现错误“此构建未生成工件”
- git - GIT推送标签第二个遥控器