I was looking at this question when I got really confused. My understanding was that the previous commit is the parent of a commit.
Asked
Active
Viewed 4.1k times
44
-
5A merge has two (or more) parents. – tkausl Jul 07 '16 at 07:13
-
1Commits form a directed acyclic graph; therefore, a commit can have zero or more parents. Here is a related question: http://stackoverflow.com/q/26395521/2541573 – jub0bs Jul 07 '16 at 07:26
-
3@Jubobs: for some reason your link isn't clickable (stackoverflow weirdness?)—ah, better/fixed now, thanks. Meanwhile, should we close this as a duplicate of that question? (I think probably yes, despite the very different *form* of the question...) – torek Jul 07 '16 at 07:29
-
1@torek Thanks. My link was missing the `http` scheme. Fixed. I'd be in favour of closing as a dupe, but I'm wary of my new "instaclose" superpowers. – jub0bs Jul 07 '16 at 07:33
-
1@Jubobs Heh, I was startled the first time I intended to "vote to close" and found that I had in fact "closed"... – torek Jul 07 '16 at 07:35
1 Answers
59
The parent commit is the commit this current commit is based on. Usually:
- When you
git commit
normally, the current commit becomes the parent commit of the new commit that's introduced by the command. - When you
git merge
two commits (or branches, whatever) without fast-forwarding, a new commit will be created with both commits as parents. You can merge more than two commits in that way, so the new commit may have more than one parent.
Essentially, the commit tree (or DAG, if we want to be accurate) is made up of those parent<-child relationships, with the children (more "recent"[1] commits) point to the parents (less "recent"[1] commits).
The only exception is the initial commit (or any other root commits), which has no parents.
- "recent" isn't exactly an accurate term, as you may have a very old branch on the one hand, and a very new one on the other. And a child commit may be a lot "older" than another commit which is a parent elsewhere.

Madara's Ghost
- 172,118
- 50
- 264
- 308