user1050619 user1050619 - 1 month ago 10
Git Question

Git merge master into branch commit ordering

I have a GIT master branch with the following commits

Master:-
commit one
commit two


Now I created a new branch sprint1 and added the following

Sprint1:
commit one
commit two
commit sprint1 one


THe master and sprint1 diverged at this point

Master:
commit one
commit two
commit three

Sprint1:
commit one
commit two
commit sprint1 one
commit sprint1 two
commit sprint1 three


Now, when I merge master into sprint1 , I get the following,

Sprint1
commit one
commit two
commit sprint1 one
commit three
commit sprint1 two
commit sprint1 three
commit merged commit


but when I merged master into sprint1 I expected this following : -

Sprint1
commit one
commit two
commit sprint1 one
commit sprint1 two
commit sprint1 three
commit three
commit merged commit


How its the former and not the latter.

Answer

According to the docs, the commits are shown in reverse chronological order.

To get the commits in the order you're expecting, try using:

git log --oneline --topo-order

This avoids showing commits on multiple lines of history intermixed.

For more details see: https://www.kernel.org/pub/software/scm/git/docs/git-log.html#_commit_ordering

You could also use --graph for a nicer output with the branch displayed separately. This implies the --topo-order option by default.

A quick log version i sometimes prefer, via an alias, is:

git --no-pager log --decorate=short --pretty=oneline --abbrev-commit --graph -n 10
Comments