There\'re few question about \"flattening merge\" on StackOverflow, with an answer usually being \"git rebase\". These answers though miss one crucial point - order of commi
[See my another answer for completely automated solution. I'd leave this as an example of path which led for ultimate solution, in case someone will face similar not-so-obvious to solve task.]
Ok, this is not real answer to the question (fully scripted, automated solution), but thinking and example how (interactive rebase based) processing can be automated.
Well, first of all, for the ultimate solution git filter-branch --parent-filter looks like exactly what's needed. Except that my git-fu doesn't allow me to wrote, 1-, 2-, or 3-liner with it, and approach to write standalone script to parse thru all revisions is not cool and more effortful than rebase -i.
So, rebase -i could be used efficiently if author dates of commit were visible. My first thought was to temporarily patch commit messages to start with author date using git filter-branch --msg-filter, run rebase -i, then unpatch messages back.
Second thought though was: why bother, better to patch rebase commit list as used by rebase -i. So, the process would be:
git rebase -iawk '/^pick/ {printf "%s %s ", $1, $2; system("echo -n git show --format='%ai' -s " $2 ""); for (i = 3; i <= NF; i++) printf " %s", $i; printf "\n"; }' git-rebase-todo > git-rebase-todo.new; mv git-rebase-todo.new git-rebase-todo sort -k3 git-rebase-todo >git-rebase-todo.new; mv git-rebase-todo.new git-rebase-todo Voila! Actually, this could be completely scripted if git rebase -i could work in "non-interactive" mode, I submitted How do I run git rebase --interactive in non-interactive manner? for that.