* cherry-pick '-m' curiosity @ 2018-02-05 11:46 Sergey Organov 2018-02-05 19:55 ` Junio C Hamano ` (2 more replies) 0 siblings, 3 replies; 7+ messages in thread From: Sergey Organov @ 2018-02-05 11:46 UTC (permalink / raw) To: git Hello, $ git help cherry-pick -m parent-number, --mainline parent-number Usually you cannot cherry-pick a merge because you do not know which side of the merge should be considered the mainline. Isn't it always the case that "mainline" is the first parent, as that's how "git merge" happens to work? Is, say, "-m 2" ever useful? -- Sergey ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: cherry-pick '-m' curiosity 2018-02-05 11:46 cherry-pick '-m' curiosity Sergey Organov @ 2018-02-05 19:55 ` Junio C Hamano 2018-02-06 13:05 ` Sergey Organov 2018-02-05 22:03 ` Stefan Beller 2018-02-19 21:39 ` G. Sylvie Davies 2 siblings, 1 reply; 7+ messages in thread From: Junio C Hamano @ 2018-02-05 19:55 UTC (permalink / raw) To: Sergey Organov; +Cc: git Sergey Organov <sorganov@gmail.com> writes: > Isn't it always the case that "mainline" is the first parent, as that's > how "git merge" happens to work? You may not be merging into the "mainline" in the first place. Imagine forking two topics at the same commit on the mainline, and merging these two topics of equal importance together into a single bigger topic, before asking the mainline to pull the whole. $ git checkout mainline $ git tag fork-point $ git checkout -b frontend-topic fork-point $ work work work $ git checkout -b backend-topic fork-point $ work work work $ git checkout -b combined $ git merge frontend-topic $ git tag merged The backend-topic may be recorded as the first-parent of the resulting merge, but logically the two topics are of equal footing, so merge^1..merge and merge^2..merge are both equally interesting. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: cherry-pick '-m' curiosity 2018-02-05 19:55 ` Junio C Hamano @ 2018-02-06 13:05 ` Sergey Organov 0 siblings, 0 replies; 7+ messages in thread From: Sergey Organov @ 2018-02-06 13:05 UTC (permalink / raw) To: Junio C Hamano; +Cc: git Junio C Hamano <gitster@pobox.com> writes: > Sergey Organov <sorganov@gmail.com> writes: > >> Isn't it always the case that "mainline" is the first parent, as that's >> how "git merge" happens to work? > > You may not be merging into the "mainline" in the first place. > > Imagine forking two topics at the same commit on the mainline, and > merging these two topics of equal importance together into a single > bigger topic, before asking the mainline to pull the whole. > > $ git checkout mainline > $ git tag fork-point > $ git checkout -b frontend-topic fork-point > $ work work work > $ git checkout -b backend-topic fork-point > $ work work work > $ git checkout -b combined > $ git merge frontend-topic > $ git tag merged > > The backend-topic may be recorded as the first-parent of the > resulting merge, but logically the two topics are of equal footing, > so merge^1..merge and merge^2..merge are both equally interesting. Point taken, thanks! Now, if I reformulate my original question as: "Isn't it _usually_ the case that "mainline" is the first parent?" what is the answer? For example, in the above case I'd likely rather: $ git checkout -b combined fork-point $ git merge --no-ff frontend-topic $ git merge --no-ff backend-topic and still have clear "mainline" on "-m1" for both merges. I'm asking because those: "Usually you cannot cherry-pick a merge because you do not know which side of the merge should be considered the mainline." in the manual page still feels confusing in the context of typical git usage (as opposed to the context of abstract DAG operations where it'd make sense indeed.) -- Sergey ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: cherry-pick '-m' curiosity 2018-02-05 11:46 cherry-pick '-m' curiosity Sergey Organov 2018-02-05 19:55 ` Junio C Hamano @ 2018-02-05 22:03 ` Stefan Beller 2018-02-06 9:25 ` Sergey Organov 2018-02-19 21:39 ` G. Sylvie Davies 2 siblings, 1 reply; 7+ messages in thread From: Stefan Beller @ 2018-02-05 22:03 UTC (permalink / raw) To: Sergey Organov; +Cc: git On Mon, Feb 5, 2018 at 3:46 AM, Sergey Organov <sorganov@gmail.com> wrote: > Hello, > > $ git help cherry-pick > > -m parent-number, --mainline parent-number > Usually you cannot cherry-pick a merge because you do not > know which side of the merge should be considered the > mainline. > > Isn't it always the case that "mainline" is the first parent, as that's > how "git merge" happens to work? > > Is, say, "-m 2" ever useful? Say you want to backport everything except that topic using cherry-picks. Then -m2 would be useful? ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: cherry-pick '-m' curiosity 2018-02-05 22:03 ` Stefan Beller @ 2018-02-06 9:25 ` Sergey Organov 0 siblings, 0 replies; 7+ messages in thread From: Sergey Organov @ 2018-02-06 9:25 UTC (permalink / raw) To: Stefan Beller; +Cc: git Stefan Beller <sbeller@google.com> writes: > On Mon, Feb 5, 2018 at 3:46 AM, Sergey Organov <sorganov@gmail.com> wrote: >> Hello, >> >> $ git help cherry-pick >> >> -m parent-number, --mainline parent-number >> Usually you cannot cherry-pick a merge because you do not >> know which side of the merge should be considered the >> mainline. >> >> Isn't it always the case that "mainline" is the first parent, as that's >> how "git merge" happens to work? >> >> Is, say, "-m 2" ever useful? > > Say you want to backport everything except that topic using cherry-picks. > Then -m2 would be useful? Didn't get the idea, sorry. Care to clarify? -- Sergey ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: cherry-pick '-m' curiosity 2018-02-05 11:46 cherry-pick '-m' curiosity Sergey Organov 2018-02-05 19:55 ` Junio C Hamano 2018-02-05 22:03 ` Stefan Beller @ 2018-02-19 21:39 ` G. Sylvie Davies 2018-02-20 16:23 ` Sergey Organov 2 siblings, 1 reply; 7+ messages in thread From: G. Sylvie Davies @ 2018-02-19 21:39 UTC (permalink / raw) To: Sergey Organov; +Cc: Git Users On Mon, Feb 5, 2018 at 3:46 AM, Sergey Organov <sorganov@gmail.com> wrote: > Hello, > > $ git help cherry-pick > > -m parent-number, --mainline parent-number > Usually you cannot cherry-pick a merge because you do not > know which side of the merge should be considered the > mainline. > > Isn't it always the case that "mainline" is the first parent, as that's > how "git merge" happens to work? > First-parent will be whatever commit you were sitting on when you typed "git merge". If you're sitting on your branch and you type "git fetch; git merge origin/master", then "mainline" will be 2nd parent. Same happens if you type "git pull". Further reading here: https://developer.atlassian.com/blog/2016/04/stop-foxtrots-now/ "git revert -m" also has the same problem. > Is, say, "-m 2" ever useful? > > -- > Sergey ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: cherry-pick '-m' curiosity 2018-02-19 21:39 ` G. Sylvie Davies @ 2018-02-20 16:23 ` Sergey Organov 0 siblings, 0 replies; 7+ messages in thread From: Sergey Organov @ 2018-02-20 16:23 UTC (permalink / raw) To: G. Sylvie Davies; +Cc: Git Users "G. Sylvie Davies" <sylvie@bit-booster.com> writes: > On Mon, Feb 5, 2018 at 3:46 AM, Sergey Organov <sorganov@gmail.com> wrote: >> Hello, >> >> $ git help cherry-pick >> >> -m parent-number, --mainline parent-number >> Usually you cannot cherry-pick a merge because you do not >> know which side of the merge should be considered the >> mainline. >> >> Isn't it always the case that "mainline" is the first parent, as that's >> how "git merge" happens to work? >> > > First-parent will be whatever commit you were sitting on when you > typed "git merge". Right, but I believe it's also "mainline", see below. > If you're sitting on your branch and you type "git fetch; git merge > origin/master", then "mainline" will be 2nd parent. No. If you ever want to cherry-pick this commit, it'd still be -m1 side of it that likely makes sense, and it's exactly the side that makes sense to be picked that is called "mainline" in the manual page we are discussing, and there is no any other definition of "mainline" as far as I can tell. There is nothing about 'origin/master' that makes it "mainline" from the POV of future cherry-picks, if any, of this merge commit. I was also unable to find any git documentation that calls 'origin/master' "mainline". It's called "remote-tracking branch", or maybe sometimes "upstream". OTOH, when one merges something, he often merges "side branch" onto "mainline", so in the context of this particular merge, your local "master" happens to be "mainline" and "origin/master" happens to be "side branch". > "git revert -m" also has the same problem. Yes, as it's essentially just "git cherry-pick --reverse -m", provided cherry-pick has had the "--reverse" from regular "patch" utility [*]. It's also interesting to notice that manual page for "git revert" refers to the revert-a-faulty-merge How-To, that in turn again uses only "git revert -m 1". Overall, it's still a mystery to me why "-m 1" is not the default behavior for both "git revert" and "git cherry-pick". The only suspicion I have is that actual intention is to deny picking merge commits by default. Then, the usual git way would be to use --force or --enable-merges to overcome the denial, but if we still do need "-m 2" etc. even rarely, then rather re-using "-m 1" as "I mean it" indication is only logical. If my suspicion is true, how about something like this: -m parent-number, --mainline parent-number This option specifies the parent number (starting from 1) of a commit and instructs cherry-pick to replay the change relative to the specified parent. Cherry-pick will refuse to handle merge commits unless this option is given. Damn, it now has no "mainline" in the description at all, so it's unclear why it has been called --mainline in the first place, not that it was somehow clear to me before. And while we are at it, I just stumbled over "git cherry-pick -m 1" refusing to handle non-merge commits: $ git cherry-pick -m1 dd5c320 error: Mainline was specified but commit dd5c320a300520a044cfa73d17f6cbffbbef60ef is not a merge. fatal: cherry-pick failed $ I wonder whether this is intentional? What's the rationale then? It seems it could be useful to be able to cherry-pick multiple commits, some of which are merges, no? Footnote: [*] rebase, revert, and cherry-pick all look rather similar in git and could be calling for some unification. -- Sergey ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-02-20 16:23 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2018-02-05 11:46 cherry-pick '-m' curiosity Sergey Organov 2018-02-05 19:55 ` Junio C Hamano 2018-02-06 13:05 ` Sergey Organov 2018-02-05 22:03 ` Stefan Beller 2018-02-06 9:25 ` Sergey Organov 2018-02-19 21:39 ` G. Sylvie Davies 2018-02-20 16:23 ` Sergey Organov
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).