user1050619 user1050619 - 1 month ago 11
Git Question

Does git merge account for commit timestamps?

Here is graph for 2 branches master and sprint1. When the 2 branches are merged I expected "second commit" (Wed Oct 19 19:58:15 2016 -0400) to be after "sprint 1 first commit" (Wed Oct 19 19:57:13 2016 -0400) as that's the time next to "sprint 1 first commit" commit time.

Question: How does the merge happen? Does the timestamp being considered affect it at all?

ds-MacBook-Pro:Test1 aks$ git log --graph
* commit 48bbcabf5d50e080c82e71ce8661571f061a35c2
|\ Merge: b59ca50 e1195c7
| | Author: hmanan <test@gmail.com>
| | Date: Wed Oct 19 19:59:53 2016 -0400
| |
| | merge commit
| |
| * commit e1195c7230fd50b3831b3c1ab597bb691c593550
| | Author: hmanan <test@gmail.com>
| | Date: Wed Oct 19 19:58:15 2016 -0400
| |
| | second commit
| |
* | commit b59ca508357f151520ce7c88c5cc439992bc477c
| | Author: hmanan <test@gmail.com>
| | Date: Wed Oct 19 19:59:22 2016 -0400
| |
| | sprint 1 third commit
| |
* | commit 68064f65d2570b8f0c22273b431444610c49d97d
|/ Author: hmanan <test@gmail.com>
| Date: Wed Oct 19 19:58:56 2016 -0400
|
| sprint 1 second commit
|
* commit f9b26255345373f2cb63d26845d2c651527e13ac
| Author: hmanan <test@gmail.com>
| Date: Wed Oct 19 19:57:13 2016 -0400
|
| Sprint 1 first commit
|
* commit faa866e8d994f32feed8c1d5e26d4d5eb4197a6f
Author: hmanan <test@gmail.com>
Date: Wed Oct 19 19:55:28 2016 -0400

first commit

Answer

As @bmargulies mentioned, the timestamps have nothing to do with how the merge is performed. A merge commit merely has pointers to two parent commits, rather than one. You can see this in the third line of your output: Merge: b59ca50 e1195c7.

To display the commits in "proper" order, use either --date-order (for committer date), or --author-date-order (for author date).

E.g.:

git log --graph --date-order
Comments