File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+
3+ # Usage: ./compare_branches.sh <upstream_branch> <head_branch>
4+ # Example: ./compare_branches.sh main feature/my-branch
5+
6+ if [ $# -lt 2 ]; then
7+ echo " Usage: $0 <upstream_branch> <head_branch>"
8+ exit 1
9+ fi
10+
11+ UPSTREAM=$1
12+ HEAD=$2
13+
14+ echo " Analyzing commits between $UPSTREAM and $HEAD ..."
15+
16+ # Get commits that are in HEAD but not in UPSTREAM (similar to git cherry)
17+ UNIQUE_COMMITS=$( git rev-list $UPSTREAM ..$HEAD )
18+
19+ if [ -z " $UNIQUE_COMMITS " ]; then
20+ echo " No unique commits found in $HEAD that aren't in $UPSTREAM ."
21+ exit 0
22+ fi
23+
24+ # Get all commit messages from upstream for comparison
25+ UPSTREAM_MSGS=$( git log --format=" %s" $UPSTREAM )
26+
27+ echo " Commits in $HEAD that aren't in $UPSTREAM based on commit message:"
28+ echo " --------------------------------------------------------------"
29+
30+ while IFS= read -r commit; do
31+ # Get the commit message for this commit
32+ COMMIT_MSG=$( git log -n 1 --format=" %s" $commit )
33+
34+ # Check if this commit message exists in upstream
35+ if ! echo " $UPSTREAM_MSGS " | grep -q " ^$COMMIT_MSG $" ; then
36+ # This commit message doesn't exist in upstream, so show it
37+ git show --no-patch --format=" %C(yellow)%h%C(reset) - %s %C(green)(%cr) %C(bold blue)<%an>%C(reset)" $commit
38+ fi
39+ done <<< " $UNIQUE_COMMITS"
You can’t perform that action at this time.
0 commit comments