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

Re: Fwd: Idea: add --squash to cherry-pick

From
Johannes Sixt <j6t@kdbg.org>
Date
Aug 11, 2022, 15:42 UTC
Message-ID
<a4c937ed-ea89-0564-db64-f0634fe7eeee@kdbg.org>
In-Reply-To
<CAO8o=D7QC71mnyKSceMpYJzVO4=POva=mJQ1bi0teUHPB9xesA@mail.gmail.com>
Am 11.08.22 um 10:53 schrieb Noam Yorav-Raphael:
Show 22 quoted lines
> The need is described in this Stack Overflow question:
> https://stackoverflow.com/q/35123108. It's fairly popular (107 votes
> for the question, 154 for the best answer), but I find the suggested
> solution lacking.
> 
> Basically, I would like to add a flag --squash to the cherry-pick
> command, that would apply the diff between the start and end of the
> specified range in one operation.
> 
> The use case is that there's a feature branch which I would like to
> apply on another branch as one commit.
> 
> I could use the `-n` flag to apply all the commits from the source
> branch without committing them. However, if there are conflicts, I
> would have to deal with them on every commit applied. Instead, what I
> want is to just apply the diff between the first and last commit, and
> then deal with the conflicts.
> 
> I find this to be a very natural operation. Usual cherry-pick applies
> the difference between commit A^ and commit A over HEAD. The suggested
> `git cherry-pick --squash A..B` would apply the difference between
> commit A and commit B over HEAD.

That question on Stackoverflow asks "how to do X with Y". But Y (git cherry-pick) is the wrong tool to do X (apply commits from a branch to somewhere else in squashed form).

   git diff A...B | git apply --3way

would do what you want. You would have to come up with a new commit message anyway, so cherry-pick would be of little use there.

-- Hannes
Previous: Noam Yorav-RaphaelNext: Junio C Hamano
Message 2 of 4 in “Fwd: Idea: add --squash to cherry-pick”
  1. Noam Yorav-RaphaelAug 11, 2022
  2. Johannes SixtAug 11, 2022
  3. Junio C HamanoAug 11, 2022
  4. Noam Yorav-RaphaelAug 12, 2022

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.