git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH/RFC] git-post: the opposite of git-cherry-pick

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 13, 2017, 10:51 UTC
Message-ID
<87wp3zs4la.fsf@evledraar.booking.com>
In-Reply-To
<3d362037-3eb6-83db-a17f-47a984135580@kdbg.org>
On Thu, Oct 05 2017, Johannes Sixt jotted:
Show 8 quoted lines
> Am 05.10.2017 um 21:33 schrieb Stefan Beller:
>> On Thu, Oct 5, 2017 at 12:13 PM, Johannes Sixt <j6t@kdbg.org> wrote:
>>> +git-post(1)
>>> +===========
>>> +
>>> +NAME
>>> +----
>>> +git-post - Apply a commit on top of a branch that is not checked out
It would be great to have this somehow, whatever the UI ends up being.
Show 13 quoted lines
>> Contrasted to:
>>    git-cherry-pick - Apply the changes introduced by some existing commits
>> Some questions on top of my head:
>> * Do we want to emphasize the cherry-pick to say checked out?
>
> Maybe. Maybe "cherry picking" is sufficiently clear that it is not needed.
>
>> * Is it a good design choice to have a different command, just because the
>>    target branch is [not] checked out?
>
> I would not want to make it a sub-mode of cherry-pick, if that is what
> you mean, because "cherry picking" is about getting something, not
> giving something away.

It occurs to me that a better long-term UI design might be to make git-{cherry-pick,pick) some sort of submodes for git-commit.

Right now git-commit picks the current index for committing, but "use a patch as the source instead" could be a submode.

Right now it commits that change on top of your checked out commit, but "other non-checked-out target commit" could be a mode instead, i.e. exposing more of the power of the underlying git-commit-tree.

Just food for thought.
Show 12 quoted lines
>> * Naming: I just searched for synonyms "opposite of cherry-picking" and
>>    came up with cherry-put, cherry-post, target-commit
>
> With command line completion, we have to type 'git cherr<TAB>-<TAB>'
> currently. If we add another command that begins with 'cherry-',
> another <TAB> is needed. Therefore, I do not want to use a name
> starting with 'cherry-'.
>
>> * What was the rationale for naming it "post" (it sounds very generic to me)?
>
> Yes, it is generic, but I did not find a better word that means "give
> away" a commit. Perhaps "tack"?

[Not entirely serious]. Well if cherry-picking is taking a thing and eating it here, maybe git-cherry-puke takes an already digested thing and "throws" it elsewhere ?:)

It's a silly name but it's somewhat symmetric :)
Show 49 quoted lines
>> * Does it play well with worktrees? (i.e. if a worktree has a branch checked
>>    out, we cannot post there, or can we?)
>
> Good point. It should be forbidden, but there are no safety checks,
> currently.
>
>>> +EXAMPLES
>>> +--------
>>> +
>>> +Assume, while working on a topic, you find and fix an unrelated bug.
>>> +Now:
>>> +
>>> +------------
>>> +$ git commit                                   <1>
>>> +$ git post master                              <2>
>>> +$ git show | git apply -R && git reset HEAD^   <3>
>>> +------------
>>> +
>>> +<1> create a commit with the fix on the current branch
>>> +<2> copy the fix onto the branch where it ought to be
>>> +<3> revert current topic branch to the unfixed state;
>>> +can also be done with `git reset --keep HEAD^` if there are no
>>> +unstaged changes in files that are modified by the fix
>>> +
>>> +Oftentimes, switching branches triggers a rebuild of a code base.
>>> +With the sequence above the branch switch can be avoided.
>>> +That said, it is good practice to test the bug fix on the
>>> +destination branch eventually.
>>
>> This is a cool and motivating example.
>
> Thanks. Another use case is when you receive a patch to be applied on
> a different branch while you are in the middle of some work. If it can
> be applied on the current branch, then you can post it to the
> destination, rewind, and continue with your work.
>
>>> +BUGS
>>> +----
>>> +
>>> +The change can be applied on `dest-branch` only if there is
>>> +no textual conflict.
>>
>> This is not a bug per se, it could be signaled via a return code that
>> the posting was unsuccessful.
>
> Oh, it does so return an error. But there are some cases that one
> expects that work, but where git-apply is not capable enough.
>
> -- Hannes
Previous: Johannes SixtNext: Johannes Sixt
Message 4 of 8 in “git-post: the opposite of git-cherry-pick”
  1. git-post: the opposite of git-cherry-pickJohannes Sixt, Oct 5, 2017
  2. Stefan BellerOct 5, 2017
  3. Johannes SixtOct 5, 2017
  4. Ævar Arnfjörð BjarmasonOct 13, 2017
  5. Johannes SixtOct 15, 2017
  6. Rafael AscensaoOct 16, 2017
  7. Johannes SixtOct 17, 2017
  8. Igor DjordjevicOct 17, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.