Last active
October 31, 2024 06:23
-
-
Save vuon9/7e9b7b8fac4401b4c037a8727d282568 to your computer and use it in GitHub Desktop.
Show git changelogs between branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To use it: | |
# show_me_git_change_logs release-v2.38.0 | |
# show_me_git_change_logs release-v2.38.0 another_branch | |
function show_me_git_change_logs() { | |
fromBranch=${1} | |
toBranch=${2:-master} | |
echo "Here are the changelogs for origin/${fromBranch}...origin/${toBranch}\n" | |
# Sort and add bullet for each item as well | |
git log --oneline --no-merges --pretty=format:%s origin/${fromBranch}...origin/${toBranch} | sort | sed 's/^/- /' | |
} | |
# Show the diff between branches as commits (1 line style) | |
# also compare the diff commits with last 100 commits of target branch to see if some of them were merged as cherry-pick | |
function show_me_git_change_logs() { | |
fromBranch=${1} | |
toBranch=${2:-master} | |
echo "\nChangelogs for ${fromBranch}...${toBranch}:\n" | |
changelogs=$(git log --oneline --no-merges --pretty=format:%s ${fromBranch}...${toBranch} | sort | while read -r commit; do | |
if git log -n 100 --pretty=format:%s ${toBranch} | grep -q "$commit"; then | |
echo "- $commit (prev)" | |
else | |
echo "- $commit" | |
fi | |
done | sort -r | uniq) | |
prev_commits=$(echo "$changelogs" | grep "(prev)") | |
new_commits=$(echo "$changelogs" | grep -v "(prev)") | |
echo "=== Merged commits (probably, as it matched to the commit on the target branch) ===" | |
echo "$prev_commits" | |
echo "\n=== New commits ===" | |
echo "$new_commits" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment