I was looking at this question when I got really confused. My understanding was that the previous commit is the parent of a commit.
Commits in git can have multiple parents, aka 'merge commits'. Using them maintains the branch history. They don't maintain the branch name, or even the history of the branch: they just tell what are the parent commits of the commit; as mentioned above, this history can be a "lie".
Every commit in git has at least one parent (except for the first/initial commit). A commit's parent is the previous one. C1 is the initial commit. C2 is the second one.
A commit can have 2 parents, which is the result of merging one branch to another in the way of "true merge". A commit can have more than 2 parents, which is the result of merging 2 or more branches to one branch at the same time, in the way of "octopus merge".
The parent commit is the commit this current commit is based on. Usually:
git commit
normally, the current commit becomes the parent commit of the new commit that's introduced by the command.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With