tags:

views:

40

answers:

2

My usual workflow with git is to create a new feature branch, do some work with frequent commits, and then merge back into the development branch when the feature is working and/or stable.

Usually, when I do git merge --squash feature-branch, I get a nice "squashed commit of the following" message that auto-populates with all of the commit messages from the feature branch.

However, if there are any merge conflicts (say I finished and merged another feature while working on this one), I seem to lose all of my commit messages from the branch. The auto-populated commit message fills in the conflicts, but not the commit messages. Where did my commit messages go? Can I get them back?

+1  A: 

Nothing is really lost with git. The list of the commits on the feature branch can be obtained using:

git cherry feature-branch

Then simply pipe this to git cat-file:

git cherry feature-branch | cut -f2 -d' ' | git cat-file --batch

You need to clean-up the output though. I don't know a way to automated it better.

gawi
+2  A: 

This doesn't answer your question directly, but you should be able to avoid the conflict in the first place.

Consider doing a

git rebase master topic

before performing the merge. The DESCTIPTION section of this page http://www.kernel.org/pub/software/scm/git/docs/git-rebase.html should be helpful.This may also obviate the need for the squash as an interactive rebase would allow you to to squash commits of your choosing.

EDIT: See also: http://stackoverflow.com/questions/2427238/in-git-what-is-the-difference-between-merge-squash-and-rebase

bc17
You definitely wouldn't need a squash merge at that point - it'd be a fast-forward.
Jefromi