DEV Community

Maroun Maroun
Maroun Maroun

Posted on


Compare Git Branches Based on the Commit Messages

Sometimes you want to compare branches based on their commit messages, and not on their SHAs.

This can be achieved by the following snippet:

git fetch
git log --format='%s' origin/branch_1 > log_1
git log --format='%s' origin/branch_2 > log_2
diff <(sort log_1) <(sort log_2)

If you want to compare local branches, you can get rid of the git fetch and remove origin for both branches.

You can generalize and write a script that accepts the branches names:


git log --format='%s' "$1" > log_1
git log --format='%s' "$2" > log_2
diff <(cat log_1 | sort) <(cat log_2 | sort)
rm log_1 log_2

Top comments (0)