2

I have a main branch and a feature branch. The feature branch is several commits ahead of the main branch, and I'd like to merge the feature branch into the main branch. I don't intend to --squash and I don't want to rebase because I like preserving the history.

I like to summarize what changed in the merge's commit message because the feature branch history can get convoluted, and a good starting point for me is to copy & edit all of the commit messages from the feature branch's assorted commits since the last merge.

I vaguely remember reading somewhere that git can compile these messages for me, but I don't remember where I read that or how to do it.

Apologies if this is a duplicate, but several Google and SO searches have failed to bring this up.

Edit: Essentially what I'm trying to do is build a changelog for everything that changed between releases.

Phlucious
  • 3,704
  • 28
  • 61
  • use `git shortlog`? – torek Jan 09 '19 at 22:13
  • Rebase will keep all the commits intact. Do you use github? With github, I create a Pull Request and merge to master. While merging, GH gives option to "squash and commit" or "keep history". Choose as required and merge. – Mohana Rao Jan 10 '19 at 00:50
  • @MohanaRao When you "squash and commit" on GitHub, don't you lose the history of the merge itself because it's not technically a merge? – Phlucious Jan 10 '19 at 23:26
  • True, in your case you choose the other option (Don't Squash). – Mohana Rao Jan 10 '19 at 23:52
  • I found this link,hope this helps. https://help.github.com/articles/about-pull-request-merges/#rebase-and-merge-your-pull-request-commits – Mohana Rao Jan 11 '19 at 00:12

3 Answers3

1

I vaguely remember reading somewhere that git can compile these messages for me

Maybe through git rebase, as shown here: don't go through the rebase (cancel it), but copy-paste the aggregated commit messages subjects shown during the rebase.

Otherwise, you could not those messages manually (as described here).

Or use a tool like antham/chyle to fetch those commit messages from your history.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I think the rebase-and-cancel option must be what I was remembering. That `chyle` option is intriguing, though. I'll have to check that out. – Phlucious Jan 11 '19 at 20:48
1

A

git log --oneline HEAD ^master

will create an output like this in git rebase -i master.

Perhaps pipe through | cat to remove the colored annotations.

ensc
  • 6,704
  • 14
  • 22
0

The --log parameter for merge is what you are looking for:

  --log[=<n>], --no-log
       In addition to branch names, populate the log message with one-line
       descriptions from at most <n> actual commits that are being merged.
       See also git-fmt-merge-msg(1).
A.H.
  • 63,967
  • 15
  • 92
  • 126