[英]Delete all local branches that have been squashed and merged
I am working on a fork of a repository.我正在开发一个存储库的分支。 I send pull requests from branches of that fork and they get "Squash and Merged" into the master branch of the upstream repository once they are accepted.
我从该分支的分支发送拉取请求,一旦它们被接受,它们就会将“压缩并合并”到上游存储库的主分支中。 How can I automatically find and delete local branches that have already been squashed and merged?
如何自动查找和删除已经被压缩和合并的本地分支? Most strategies shown in other solutions rely on determining whether all commits in a branch can be found in master's commit history, but since all my commits are squashed this condition is never met.
其他解决方案中显示的大多数策略都依赖于确定是否可以在 master 的提交历史中找到分支中的所有提交,但是由于我的所有提交都被压缩,所以这个条件永远不会满足。
My git remote -v
looks like:我的
git remote -v
看起来像:
origin git@github.com:sshleifer/transformers_fork.git (fetch)
origin git@github.com:sshleifer/transformers_fork.git (push)
upstream git@github.com:huggingface/transformers.git (fetch)
upstream git@github.com:huggingface/transformers.git (push)
Through git alone: the short answer is you can't (not with 100% reliability).通过 git 单独:简短的回答是你不能(不是 100% 的可靠性)。
Here are some unreliable ways to explore:以下是一些不可靠的探索方式:
fix #xyz
in some commit message?);fix #xyz
?);^{tree}
) in your branch matches the content of a commit on master:^{tree}
)是否与 master 上的提交内容匹配:
git log --first-parent --format="%T"
will give you the list of trees on master, git log --first-parent --format="%T"
会给你master上的树列表,git rev-parse branch/name^{tree}
will give you the tree for branch branch/name
git rev-parse branch/name^{tree}
将为您提供分支branch/name
的树If you can persuade the owners of the upstream repository, you could use a workflow where instead of generating pull requests from the fork to some long-lived branch of the upstream, you instead generate pull requests against a short-lived feature branch that has the exact same name as the branch you are pushing, and then separately the administrator can manage a pull request from that feature branch (in the upstream) to the long-lived branch.如果您可以说服上游存储库的所有者,您可以使用工作流,而不是从分支生成拉取请求到上游的某个长期存在的分支,而是针对具有短期特性的分支生成拉取请求与您正在推送的分支完全相同的名称,然后管理员可以单独管理从该功能分支(在上游)到长期分支的拉取请求。 If this deletes the feature branch upon the squash merge, then you could detect when upstream feature branches are deleted with
remote prune
.如果这会在 squash 合并时删除功能分支,那么您可以检测到上游功能分支何时被
remote prune
删除。
# My PR to upstream creates a new feature branch
fork:my-feature-branch -> upstream:my-feature-branch
# Upstream deals with merging to long-lived branch
# this operation will delete upstream:my-feature-branch
upstream:my-feature-branch -> upstream:develop
# I synchronize my fork with upstream and observe branches removed
# with remote prune, and either manually or programmatically delete
# the fork: version of those branches.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.