Git Commit Parents' Order

libgit2 and its bindings return the parents in the order that they're stored in the commit, which is the order of the commits as they were given on e.g. the command-line for git merge, and it's a constant that the first parent is the current commit when creating a new one (either through merge or normal git commit).

In order to identify the commit previous commit (in time), then all you need to do is look at the first parent. Whether they're in the same branch or not is not something you can see from that, as a commit parent might be in a different branch (which is what causes branches), but you can draw a direct line (like those git log --graph --oneline draws).


Yes, if you merge A into B, the first parent is B and the second is A.

Therefore you can do things like gitk --first-parent to show the history of only the current branch without details of the merged-in branches.