I'm trying to revert the latest commit done on the branch (by someone else). I'm using TortoiseGit client. When I click "Revert changes by this commit", git offers two choices: Parent1
and Parent2
. What does this mean? What is Parent1 and what is Parent2?
-
1Also have a look at http://stackoverflow.com/questions/5970889/why-does-git-revert-complain-about-a-missing-m-option – Bruno E. Sep 05 '16 at 07:22
2 Answers
Every commit in git has at least one parent (except for the first/initial commit). A commit's parent is the previous one.
C1 <- C2 <- C3
C1 is the initial commit. C2 is the second one. C1 is the parent of C2. The same goes to C3.
A merge commit is a special commit in the sense of the number of parents.
C1 <- C2 <- C3
\
.. C4 <- C5 <- C6
C6 is a merge commit. It has two parents, C3 and C5. If you merged the two branches (commits) when you were at C5: C5 is said to be Parent 1 (first parent) and C3 is Parent 2 (second parent).

- 3,416
- 2
- 34
- 37
-
And with regards to "accessing" parents from a commit-ish references you can use `^`. E.g. `C6^`, which is really a shorthand for `C6^1` which is the first parent of `C6`. To refer to the second parent, e.g. `C3` the reference is `C6^2`. – hlovdal Dec 19 '22 at 00:57
It appears that you are trying to revert a merge commit in your branch. A merge commit has two parents, one for each branch involved in the merge. You need to choose which parent's version of history you want to retain. You should check each parent and decide which one you want to retain. Most likely, you probably want to retain the parent commit which appears in the php7
branch. This should be the Parent 1
option in the drop down.
php7 A -- B -- M <-- retain this parent's version of history
/
master .. C

- 502,043
- 27
- 286
- 360