git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Johannes Sixt <j6t@kdbg.org>
To: Noam Yorav-Raphael <noamraph@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Fwd: Idea: add --squash to cherry-pick
Date: Thu, 11 Aug 2022 17:42:15 +0200	[thread overview]
Message-ID: <a4c937ed-ea89-0564-db64-f0634fe7eeee@kdbg.org> (raw)
In-Reply-To: <CAO8o=D7QC71mnyKSceMpYJzVO4=POva=mJQ1bi0teUHPB9xesA@mail.gmail.com>

Am 11.08.22 um 10:53 schrieb Noam Yorav-Raphael:
> 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

  reply	other threads:[~2022-08-11 15:51 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAO8o=D6p+aFOeRdTDHwPa1E+V45Uqh-TuSZbz0WU=rE-ksGj_w@mail.gmail.com>
2022-08-11  8:53 ` Fwd: Idea: add --squash to cherry-pick Noam Yorav-Raphael
2022-08-11 15:42   ` Johannes Sixt [this message]
2022-08-11 16:43     ` Junio C Hamano
2022-08-12  8:37       ` Noam Yorav-Raphael

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a4c937ed-ea89-0564-db64-f0634fe7eeee@kdbg.org \
    --to=j6t@kdbg.org \
    --cc=git@vger.kernel.org \
    --cc=noamraph@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).