Add script to find merged branches when squashed on merge

This commit is contained in:
2026-08-04 10:50:51 +01:00
parent 5dca3ec13b
commit 1f422ae532

17
git-find-merged Executable file
View File

@@ -0,0 +1,17 @@
#!/bin/bash
# Find local branches that have been squash-merged into a target branch.
# Usage: git-find-merged [target-branch]
# Default target branch: main
target="${1:-main}"
git for-each-ref refs/heads/ --format='%(refname:short)' | while read branch; do
[[ "$branch" == "$target" ]] && continue
merge_base=$(git merge-base "$target" "$branch" 2>/dev/null) || continue
tree=$(git rev-parse "$branch^{tree}" 2>/dev/null) || continue
squash_commit=$(git commit-tree "$tree" -p "$merge_base" -m "test" 2>/dev/null) || continue
cherry_result=$(git cherry "$target" "$squash_commit" 2>/dev/null)
if [[ "$cherry_result" == "-"* ]]; then
echo "$branch"
fi
done