cherry pick
Is it correct that F '= (FB) + Z?
No, it will also lead to the changes that have been made to C , D and E.
git-cherry-pick works by isolating the unique commit changes that will be selected by the cherry (i.e., FE in this example, ignoring additional ancestors, including the merge base) and apply them to the target.
This is not done using the patch application, but using a three-way merge algorithm - the parent commit element, which will be selected by cherry, will be used as a common ancestor, and the commit will be selected by cherries, there will be one side of the merge, with the goal, like on the other side . The result of this is the changes that were included in the cherry picker and in the target.
For example, if E is the parent fixation element selected from cherry and its contents (acting as a common ancestor):
Line 1 Line 2 Line 3 Line 4 Line 5
For example, if F is the fixation selected by the cherry and its contents:
Line 1 Line 2 Line Three Line 4 Line 5
And the goal of the cherry pick Z is:
LINE 1 Line 2 Line 3 Line 4 Line 5!
Then the results of a three-way merger (with annotations about where each line came from):
LINE 1 Line 2 Line Three Line 4 Line 5!
Revert
Is it correct that D '= G - D?
Yes, roughly speaking. Changes that were unique to D were removed from G. Like git-cherry-pick , git-revert is implemented using a three-way merge, although this time the commit to return is considered a common ancestor, one side is the current commit, and the other side is the commit to return the parent.
This will mean that when the line is identical between the commit and return and the current commit, a row from its parent will be selected instead.
If the contents of D , the commit to return acts as a common ancestor, and its contents:
Line 1 Line 2 Line THREE Line 4 Line FIVE
And the contents of C ( D ):
Line 1 Line 2 Line 3 Line 4 Line 5
And the contents of G were changed additionally, and its contents:
Line One Line 2 Line THREE Line 4 Line FIVE
Then the results of the tripartite merger will be:
Line One Line 2 Line 3 Line 4 Line 5
This is the result of using unique strings in the parent C and target G.
Merge commits
Like torek notes (below), since these mechanisms include the use of a parent commit, they break when there is more than one parent commit. (That is, the transaction in question is a merger and has several parents.) In this case, you need to tell git which parent should consider (using the -m flag).
Conflicts
Of course, any of these mechanisms can cause conflicts. For example, if the current conflict has changed even more, you will have to resolve the conflicts. For example, if in the return example (above), the subsequent commit also changed line 5, then G :
Line One Line 2 Line THREE Line 4 LINE FIVE!
Then a conflict arose. The working directory (combined file) will look like this:
Line One Line 2 Line 3 Line 4 <<<<<<< LINE FIVE! ======= Line 5 >>>>>>>
And you will need to decide whether you want the initial change ( Line 5 ) or the newest change ( LINE FIVE! ).