This answer to a previous question on StackOverflow suggests the base used for the cherry-pick command is the parent of the commit to be cherry-picked. It makes a lot of sense to me, but I wanted to possibly verify it using the official documentation from git developers. Does anyone know where I can find the official documentation?
Asked
Active
Viewed 68 times
-2
-
3I think the problem you're going to have is that once you think about what cherry-pick is doing and understand Git's structure, the pick operation is so obviously exactly what you've been told it literally goes without saying. [The official cherry-pick docs](https://git-scm.com/docs/git-cherry-pick) (the book's reference section is a reformat of the man pages) talk about conflicts and point you at the merge docs to see how the mechanics of conflict resolution work. – jthill Jul 31 '22 at 00:19
-
2Also note the `-m` (aka `--parent-number`) option: this option only makes sense if we're going to use *a* parent of the commit during the merge process, and the fact that it's required only when the commit *is* a merge commit (and until recently, was forbidden and implied to be 1 when the commit wasn't a merge commit) tells you the rest. – torek Jul 31 '22 at 04:04
-
@torek The information you provided is helpful. But, I think it still does not 100% clarify base selection. The parent number may be exclusively used in the _diff_ step. As you pointed out in the original response, at some point in the past, the _diff_ step was present while the implementation of cherry-pick was not exactly how it is today. – H D Aug 01 '22 at 23:25
-
@torek BTW, I have a clarifying question. In the example you provided in your original response, the diff calculated between commits H and E, in a common representative scenario, includes the changes implemented in transitioning from D to E as deletions and the changes implemented in transitioning from D to G, and G to H, as additions. Am I right? – H D Aug 01 '22 at 23:29
-
1It's true that back when it was just `git diff ... | git apply` (more or less), the `-m` option just selected the parent for the first diff. But to do a merge at all, the parent must be the *same commit* in *both diffs*. Merge depends on this! Re the clarifying question: you can think of it that way, but remember, each commit stores a full snapshot, so you don't even have to *ask* what's in any intermediate commit. – torek Aug 01 '22 at 23:33
-
@torek Thank you. I get that each commit stores a full snapshot. I just found it interesting that during the operation of cherry-pick, the good changes applied in the transition from D to E are sort of treated like bad changes that should be deleted. Of course, this is just a means to get the end goal of cherry-pick. – H D Aug 02 '22 at 00:31
-
1So @HD what do you think the oft repeated explanation of how cherry pick works _is?_ A cult? – matt Aug 02 '22 at 01:08
-
@matt Most of the sources that talk about the cherry-pick command describe it only at a high level. I was very happy/lucky to see the answer mentioned above that described the operational steps of cherry-pick, which in my humble opinion, are key to getting a _true_ understanding of what cherry-pick does. – H D Aug 02 '22 at 07:15
-
@matt hahaha oh, man. I wanna be the **cherry-pick** priest, if the position is available. – eftshift0 Aug 02 '22 at 10:41
-
@HD I agree they are essential to a true understanding. What I'm asking is, now that you have that understanding, what's _this_ question about? We are programmers, not epistemologists. – matt Aug 02 '22 at 10:47
-
@matt Well, That was literally the only source I'd seen that provided those details. Following that two thoughts popped up in my mind: (i) It would be nice to find additional evidence, specially from Git developers, to verify those details. (No offense to the generous StackOverflow (SO) author who spent all the time to explain the details. But that's just the right thing to do generally in life, I think). – H D Aug 02 '22 at 18:17
-
@matt (ii) I was wondering if there is a good comprehensive documentation about Git I am missing. Honestly, it is still kind of hard to believe that seemingly there does not exist any official documentation by Git explaining what the SO author had explained. – H D Aug 02 '22 at 18:17
-
Asking for an explanatory resource is off-topic for SO. Anyhow, you've been shown the source code! You can't get closer to "additional evidence, specially from Git developers" than that. You're looking right at that evidence — and you seemingly won't accept it, because "it is hard for me to read" the code. Well, tough nuggies! You've got your evidence, and if you're all that interested in the proof you're after, you'll learn enough to read the code. Otherwise, just accept what you've been told by people who _can_ read the code, like torek. – matt Aug 02 '22 at 18:22
-
@matt The good point about posting this question is that I now have more evidence than a single answer to a single SO question to back my understanding of the cherry-pick command. I hope that clarifies your doubts. :) – H D Aug 02 '22 at 18:39
-
@HD You haven't accepted the answer, so it doesn't. – matt Aug 02 '22 at 19:16
-
@matt I just did. – H D Aug 02 '22 at 19:35
1 Answers
3
I do not think anything will beat code. Look around here (and the code before it inside do_pick_commit
):
https://github.com/git/git/blob/master/sequencer.c#L2182-L2225

eftshift0
- 26,375
- 3
- 36
- 60
-
Thank you. It is hard for me to read and interpret the code. Were you able to verify that the base used for the underlying merge is a *tunable parent of the target commit*? I said _tunable_ because it seems like it can be adjusted using the [argument](https://git-scm.com/docs/git-cherry-pick) -m
. – H D Aug 01 '22 at 23:34 -
It's tunable for a merge commit, yes, of course, because that is a commit with multiple parents so you need to specify which one. Other commits have just one parent and that's the one. – matt Aug 02 '22 at 01:06