Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git revert - git asking parent1 or parent2

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?

screenshot

like image 376
srgb Avatar asked Sep 05 '16 07:09

srgb


People also ask

What is Parent 1 and Parent 2 in git?

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.

How do I fix git revert?

The fix is pretty simple. Whenever you do a “git revert,” Git makes a new commit with opposite changes to the commit being reverted. If you created a file, that file is removed, and the commit reflects that. The fix is to apply that reverting commit, and then revert it back, which will un-revert the changes.

What is git revert M option?

To revert the merge commit we should tell git how we want it to revert the changes. The -m option is used to specify the parent commit that the new commit should replicate. In our example, the faulty merge has two parents; c2 of the master branch is the first parent and C4 of the feature branch is the second parent.

How do you revert a commit with two parents?

REVERTING THE MERGE COMMIT The parent may be specified with the -m flag in git revert followed by the parent-number. The parent number is assigned from left. To revert the changes brought in by the feature branch, revert the commit with respect to the second parent (1484b1a).


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).

like image 128
joker Avatar answered Oct 07 '22 00:10

joker


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
like image 31
Tim Biegeleisen Avatar answered Oct 07 '22 01:10

Tim Biegeleisen