Reputation: 179
I am using a successful git branching model, where you have master
branch only consisting from merge commits with version tags, and all the development goes on develop
branch.
The develop
branch also consists of merge commits (feature branches) and ordinary commits (small individual changes).
When I perform a new version release, I want git to make me a chengelog. git merge develop --log
does this, but this "unrolls" merge commits on develop
, resulting in a flat history.
I want to make 'git merge --log' use only commits on develop
, is this possible?
Examples:
What I atually get now when merging:
Merge branch 'develop' into master
* develop:
fix 1 on branch develop
fix 2 on branch develop
fix 1 on branch b1
fix 2 on branch b1
fix 3 on branch b1
fix 1 on branch b2
fix 2 on branch b2
fix 1 on branch b3
What I want it to be:
Merge branch 'develop' into master
* develop:
fix 1 on branch develop
fix 2 on branch develop
Merge branch 'b1' into develop
Merge branch 'b2' into develop
Merge branch 'b3' into develop
Upvotes: 1
Views: 269
Reputation: 60275
To get the log you want for an inflight merge, use
git log --pretty=' %s' --first-parent ..MERGE_HEAD # with e.g. `-10` to limit to 10
or to see what that'd get from an existing merge use merge^1..merge^2
as your range.
The quickest way to get to a smoketest is probably git merge --log=1
to generate the right boilerplate, then in vim it'd be
:/^\*/+,+!git log --pretty=' \%s' --first-parent ..MERGE_HEAD
to fill in the log the way you want. To automate it you'll need to use the prepare-commit-msg
hook, something along the lines of
case $2 in
merge)
git log --pretty=' %s' --first-parent ..MERGE_HEAD >${tempfile=`mktemp`}
sed -i '/^\*/,/^$/ { //!d }; /^\*/ r '$tempfile "$1"
rm $tempfile
;;
esac
edit: on GNU/anything, the hook gets simpler because the sed's buffier:
case $2 in
merge)
git log --pretty=' %s' --first-parent ..MERGE_HEAD \
| sed -i '/^\*/,/^$/ { //!d }; /^\*/ r /dev/stdin' "$1"
;;
esac
Upvotes: 1