Who was my first parent? [Git]

A co-worker of mine had the following tree structure in his git repository and he wanted to get rid of the 2abaf35 and 607f016 commits. The solution is a simple

git reset --hard e5e67d0

But, for the sake of fun, I wanted to do it without referring to a SHA value. The HEAD commit has two parents e5e67d0 and 2abaf35. HEAD^ will refer to the first parent and HEAD^2 will refer to the second parent. But how do we know which parent is the first?

According to charon at #git on freenode, HEAD at the time of invoking the merge will always be the first parent. This is the left-most (straight line) branch. The remaining commits will be the remaining parents, in the order you specify. So, in this case,

git reset --hard HEAD^

would have achieved the same feat.

Post a comment or leave a trackback: Trackback URL.

Leave a Reply